Python - manually install package using virtualenv
Asked Answered
E

4

93

I have a python program I want to install into my virtualenv - it's a zip package that I need to unzip and then run a setup.py program - but my question is more regarding how to get these unzipped files into my virtualenv so that the package gets installed into the virtualenv's site-packages folder?

I can also install from inside my virtualenv using pip install <package name>, but for some reason, the package that PIP downloads is out of date.

So - can someone tell me a few easy steps for installing a package manually?

So far I have the basic commands to load up the Virtualenv:

-bash-3.2$ source ~/.bashrc
-bash-3.2$ workon test
(test)-bash-3.2$ //Now I'm working on my virtualenv, but where do I go after this??

So - does it matter where I unzip the python package/program to - or should I be logged in to the virtualenv first before unzipping? After I load up the virtualenv and I'm inside using it with the 'workon test' command, will any python package I install, regardless of the directory I find it, install itself into the proper virtualenv's site-packages folder?

Option 1 is to unzip the python program into /home/username/tmp - then log into my virtualenv, navigate to that folder and run the setup.py program - assuming that the virtualenv will transfer all relevant files to it's own site-packages folder.

OR scenario 2 is to unzip the files directly into site-packages, and run it from there (after logging in to the virtualenv), etc

Thank you for helping a Python clutz with this!

Evacuation answered 12/5, 2011 at 14:26 Comment(0)
V
142

I typically would extract the program to a temporary folder, then from that folder, run the setup.py using the direct path to the virtualenv python instance. eg if your virtualenv is in /home/username/virtualpy, use this (from your temporary folder)

/home/username/virtualpy/bin/python setup.py install

This should install it to your virtualenv site package folder.

Vigilance answered 12/5, 2011 at 14:42 Comment(3)
So really the import operation is to run python using the version of python (2.6) installed in the virtualenv...nice! Thanks Dwelch.Evacuation
Make sure you run it from the temporary folder; setup.py will likely expect it to be the current folder.Counterintelligence
This doesn't seem to be necessary any longer. Once the virtual env is activated, i just run python setup.py install or python setup.py develop and it installs in the right place.Prosenchyma
E
16

well when you switch to the virtual environment. you should type

which python

and if it returns the path where your virtual environment exists then its okay you can directly run this command.

$ python setup.py build
$ python setup.py install

but if it gives the global level path which is not your virtualenv's path then you should try using

$ ~/.virtualenv/python-env/bin/python setup.py build
$ ~/.virtualenv/python-env/bin/python setup.py install
Entwine answered 5/5, 2016 at 14:36 Comment(0)
H
0

If a package won't install from repository, try under venv by use sudo. As example for python pathos package;

/venv3.6/bin$ sudo pip3 install pathos
Hom answered 5/2, 2019 at 7:22 Comment(0)
J
0

PACKAGE_DIR=/some/package/directory/path export VENV=$(pipenv --venv) && export BASE_DIR=$(pwd) && cd $PACKAGE_DIR && $VENV/bin/python setup.py install && cd $BASE_DIR

Jaquenette answered 1/12, 2019 at 17:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.