2

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?

JerryBringer
  • 150
  • 1
  • 1
  • 8

1 Answers1

1

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.

sufi
  • 157
  • 3
  • 10
  • 1
    This is exactly what I ended up doing. Im accepting because this is a very well explained answer with step by steps instructions. I can appreciate anyone who goes the extra mile on the answers they give, Thanks sufi!!! – JerryBringer Dec 10 '18 at 16:01