Revert the `--no-site-packages` option with virtualenv

前端 未结 5 2096
暖寄归人
暖寄归人 2020-11-28 02:39

I have created a virtualenv using the --no-site-packages option and installed lots of libraries. Now I would like to revert the --no-site-packages

相关标签:
5条回答
  • 2020-11-28 03:01

    Try removing (or renaming) the file no-global-site-packages.txt in your Lib folder under your virtual environment.

    Where venv is the name of your virtual environment, and python3.4 corresponds to whichever version of python involved, for example:

    $ rm venv/lib/python3.4/no-global-site-packages.txt
    

    And if you change your mind and want to put it back:

    $ touch venv/lib/python3.4/no-global-site-packages.txt
    

    Note: If you don't see the above file, then you have a newer version of virtualenv. You'll want to follow this answer instead

    0 讨论(0)
  • 2020-11-28 03:02

    Go to your venv folder and open pyvenv.cfg. (E.g. if your virtual environment is called myenv then the file will be located at myenv\pyvenv.cfg)

    You'll see a boolean setting called include-system-site-packages

    Set that setting to true to use global packages

    If you want to disable using global packages, just set that setting to false instead.

    0 讨论(0)
  • 2020-11-28 03:03

    At least for Python 3.5.2, there is pyvenv.cfg file in the root of virtualenv directory. All you need to do is to change include-system-site-packages flag from false to true:

    home = /usr/bin
    include-system-site-packages = false  # <- change this to "true"
    version = 3.5.2
    
    0 讨论(0)
  • 2020-11-28 03:05

    Try adding a symlink between /virtualenv_root/lib/ and /path/to/desired/site-packages/

    0 讨论(0)
  • 2020-11-28 03:06

    When using virtualenvwrapper to manage virtualenvs, you can use the shell function toggleglobalsitepackages to switch between using and not using site packages.

    0 讨论(0)
提交回复
热议问题