简体   繁体   中英

in `pyenv/pyenv-virtualenv` can I create a virtualenv which refers to `system`, i.e. without a `pyenv install` before?

Hello I am using pyenv and its plugin pyenv-virtualenv .

Normally I would install a pyenv first (eg pyenv install 3.7.6 ) and then a virtualenv (eg pyenv virtualenv 3.7.6 myenv ) and then proceed with pip install .

This time, as the system already features python 3.7, and because I am short of disk space (I'm on a Raspberry Pi 3, with buster ), I would like to avoid installing the whole python, but still I would like to isolate in a user-space virtualenv the python packages (numpy, pandas, ecc.). So I would like to define a virtualenv that uses the system python3.

I tried pyenv virtualenv system sysenv but it doesn't work (it claims it can't find pip):

$ pyenv virtualenv system sysenv
Traceback (most recent call last):
  File "/usr/bin/pip", line 7, in <module>
    from pip._internal.main import main
ModuleNotFoundError: No module named 'pip'

which I don't understand, as I have both python-pip and python3-pip apt packages installed.

So: is it possible to create a virtualenv that uses the system python3? What do I miss? Or, is it a bad idea as the system python might be upgraded by apt later?

You can just use virtualenv without pyenv.

eg

$ virtualenv -p $(which python3) sysenv

I can't remember if this command activates the env, so if not you can then run

$ source sysenv/bin/activate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM