2

I try to install a package with pip in a virtual environement previously created with venv. The Python version is managed through pyenv. I don't want to use pyenv to create the virtual environment.

The project is set up this way. To the project empty directory, I added a .python-version containing the version 3.8.2. Then I created my virtual environement using python -m venv .venv. Then I activated the environement using source .venv/bin/activate. Now the command line starts with a (.env). However, when I try to install some package with pip install some-package, the package ends up in {pyen_home}/versions/3.8.2/lib/python3.8/site-packages, instead of the virtual environment.

What's irritating is that I'm almost certain that I did manage to install package in the virtual environment that way before, but not anymore, so I don't see what I'm missing.

runningwild
  • 129
  • 12

1 Answers1

1

Content of your .python-version should be .venv.

As far as I know you should not create this file by yourself. It generated when you run pyenv local .venv. And venv activates automatically.

Also proper way to create virtual environment is pyenv virtualenv {python-version} {venv-name}. Read the docs carefully.

teplandr
  • 176
  • 1
  • 9
  • I preferred to manage the env myself (doc says it is possible) and not use `pyenv virtualenv`, but I think I may have to resort to it in th end. Also I'm not sure about your first claim about the content of `.python-version` but thanks for pointing out `pyenv local .venv`. – runningwild Mar 21 '22 at 16:32
  • What is the content of `.python-version` after you run `pyenv local .venv`? I suppose the same as in my first claim. – teplandr Mar 21 '22 at 16:41
  • @runningwild, may be you accept my answer?) – teplandr Mar 23 '22 at 02:12
  • If I for first create the `.venv` in the project directory with the command indicated in my question, `pyenv local .venv` returns "pyenv: version .venv not installed". This makes sense: `pyenv` looks for `.env` under the centralised `.pyenv`, like the other Python versions it manages. It doesn't look in the local directory. – runningwild Mar 23 '22 at 22:19
  • I upvoted your answer as it provides useful information, however it doesn't really answer the question. I made more clear that I want to manage the virtual environement myself and not delegate it to `pyenv`. That's what I meant by "created with `venv`. – runningwild Mar 23 '22 at 22:25