I have a pytest test, let's call it test.py
. I used to run this test outside of virtualenv; now I'm trying to run it inside a virtualenv sandbox.
The project is structured like this:
~/project/test # where test.py and all virtualenv files live
~/project/mylibrary
test.py
imports from mylibrary
. In the past, this worked because I have the code in ~/project/mylibrary
installed into /usr/lib/python2.7/dist-packages/mylibrary
.
I can't run virtualenv with the --system-site-packages
flag. I also can't move the code from ~/project/mylibrary
into the ~/project/test
folder. How can I get access to the code in mylibrary inside my virtualenv?
You don't need to do anything special - as long as you are working inside a virtualenv, python setup.py install
will automatically install packages into
$VIRTUAL_ENV/lib/python2.7/site-packages
rather than your system-wide
/usr/lib/python2.7/dist-packages
directory.
In general it's better to use pip install mylibrary/
, since this way you can neatly uninstall the package using pip uninstall mylibrary
.
If you're installing a working copy of some code that you're developing, it might be a good idea to install it in "editable" mode using pip install -e mylibrary/
, which creates a link to your source directory so that your installed module gets updated as you edit the code.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句