How to add new default packages to virtualenv?

这一生的挚爱 提交于 2020-05-15 05:47:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!