How to import a globally installed package to virtualenv folder

Question:

So I have a virtualenv folder called venv for my python project.

I can run:

venv/bin/pip install -r requirements.txt

Which installs all requirements I need for the project except one, M2Crypto. The only way to install it is through apt-get:

apt-get install python-m2crypto

How can I then add this package installed through apt to venv folder?

Asked By: Richard Knop

||

Answers:

venv/bin/pip install -I M2Crypto

The -I forces it to also be installed into the virtualenv, even if it’s already globally installed.

Answered By: Amber
--system-site-packages

gives access to the global site-packages modules to the virtual environment.

you could do:

$ sudo apt-get install python-m2crypto
$ virtualenv env --system-site-packages

… and you would then have access to m2crypto (along with all other system-wide installed packages) inside your virtualenv.

Answered By: Corey Goldberg

What I did after all:

cp -R /usr/lib/python2.7/dist-packages/M2Crypto /home/richard/hello-project/venv/lib/python2.7/site-packages/
cp -R /usr/lib/python2.7/dist-packages/OpenSSL /home/richard/hello-project/venv/lib/python2.7/site-packages/
Answered By: Richard Knop

toggleglobalsitepackages will toggle access to the system-wide site-packages.

Note: You need to pip install virtualenvwrapper to get this command; the vanilla virtualenv doesn’t include it. With virtualenvwrapper you also get the very useful mkvirtualenv and rmvirtualenv commands, among others.

Answered By: Will

Real simple solution.

In the virtual environment directory, edit the file pyvenv.cfg. Set the parameter include-system-site-packages = true, and save the file.
The globally installed modules will appear the next time you activate (source venv/bin/activate) your environment.

It can be verified via pip list.

Enjoy!

Answered By: roshnet

The only way to transfer packages locally from one environment or global to the other virtual environment is
Copying the the "Lib"folder or the package folder with all its contents from the environment to the other environment you want the package to work

If you don’t know it’s location search for it within the environment folder using file explorer

Lib folder contains all the installed packages of the environment

Answered By: Rabbi kindalo
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.