JerryBringer
JerryBringer

Reputation: 160

Can I create a virtualenv after making the mistake of installing all project packages globally?

So I am a python newb like first project ever newb. I jumped right in disregarding virtualenv and installed everything globally. Now I need to be able to share my project with other team members.

Can I create a virtualenv after making the mistake of installing all project packages globally?

I am using python 3. I've read these links: pip installing in global site-packages instead of virtualenv How to import a globally installed package to virtualenv folder

But I don't think thats what Im looking for. I want to go the requirements.txt route I think.

Any guidance or suggestions?

Upvotes: 2

Views: 1395

Answers (1)

sufjak
sufjak

Reputation: 157

Yes, you can create a virtual env.

You can create a requirements.txt file for the packages you installed globally.

pip3 freeze > requirements.txt

and then you can use this requirements file for installing all the packages in the virtual env which will be isolated from your global environment. First you need to install virtualenv:

pip3 install virtualenv

Create a new virtual env using the following command:

virtualenv -p python3 envname

You can activate the virtualenv by:

source /path/to/new/virtual/environment/bin/activate

To deactivate the environment and return to your local environment just run:

deactivate

Install the requirements from the file.

cat requirements.txt | xargs -n 1 pip3 install

This should install all your packages in the virtual environment.

To check which python you are using use which python command and to check installed packages use pip3 list

I hope this will clear your doubt.

Upvotes: 1

Related Questions