Reputation: 3661
I have multiple python projects, each with its own virtual environment. Additionally I have a global python environment. I want to share the same package files between virtual/global environments without copying them multiple times (where possible).
Environment Packages
----------------------------------------
GLOBAL: A B C D
VENV_1: A B C E
VENV_2: C D F
So, in this example:
C
.GLOBAL
and VENV_1
will also share files for A
and B
.GLOBAL
and VENV_2
will share files for D
.E
and F
are not globally installed, then the virtual environments will install those packages individually.I tried using virtualenv
with the --system-site-packages
flag, but that just makes all global packages accessible in the virtual environment. So when I export my environment using pip freeze
it will contain unnecessary packages.
How can I create a virtual environment with select packages, such that if a package is globally installed, a new copy of files for that package won't be made locally? Is this possible using conda
or virtualenv
or any other tool?
I am using Windows 10 with python 3.6.
Upvotes: 5
Views: 3506
Reputation: 3846
~/.pip/cache
so it won't need to download them again next time by adding the following to $HOME/.pip/pip.conf
:[global]
download_cache = ~/.pip/cache
Then, for each user who will have access, edit the .condarc
file found in their home directory with the following entry, specifying the full path to that shared directory:
pkgs_dirs:
- /path/to/shared_directory
Windows - C:\Users\username.condarc
macOS and Linux - /home/username/.condarc
Verify the package cache by running conda info
.
Upvotes: 0
Reputation: 3323
With PyCharm you can associate projects, and you could probably manipulate the PYTHONPATH variables in your venv/Source/activate.bat file but I think you are barking up the wrong tree.
I believe you would be much better off setting up a private PyPi Server (example). In so doing, you could pip-install into your new project - with the added advantage of version control and other goodness. Otherwise, you are really just undoing much of the encapsulation benefits that virtual environments give you in the first place.
Upvotes: 0