问题
When I create a virtualenv, it installs setuptools and pip. Is it possible to add new packages to this list?
Example use cases:
- Following this solution to use ipython in virtualenv (from this question) requires installing ipython in every virtualenv (unless I allow system-site-packages).
- Or if I'm doing a only flask/pygame/frameworkp development, I'd want it in every virtualenv.
回答1:
You can use bootstrap scripts to do whatever you want See https://virtualenv.pypa.io/en/latest/reference.html#creating-your-own-bootstrap-scripts
I have no experience using this, but it appears to be what you want, from the manual.
回答2:
I took a different approach from what is chosen as the correct answer.
I chose I directory, like ~/.virtualenv/deps and installed packages in there by doing
pip install -U --target ~/.virtualenv/deps ...
Next on postmkvirtualenv I put the following:
# find directory
SITEDIR=$(virtualenvwrapper_get_site_packages_dir)
PYVER=$(virtualenvwrapper_get_python_version)
# create new .pth file with our path depending of python version
if [[ $PYVER == 3* ]];
then
echo "/Users/home/.virtualenvs/elpydeps3/" > "$SITEDIR/extra.pth";
else
echo "/Users/home/.virtualenvs/elpydeps/" > "$SITEDIR/extra.pth";
fi
Post that basically says the same thing
来源:https://stackoverflow.com/questions/12025100/how-to-add-new-default-packages-to-virtualenv