admin管理员组

文章数量:1390803

I have created a project folder with a pyproject.toml, but I want to use the same virtualenv created in the ProjectA in ProjectB, how can I do that ?

Whenever I use the poetry env use /full/path/python.exe, it basically creates another venv for me which I want to avoid.

I have created a project folder with a pyproject.toml, but I want to use the same virtualenv created in the ProjectA in ProjectB, how can I do that ?

Whenever I use the poetry env use /full/path/python.exe, it basically creates another venv for me which I want to avoid.

Share Improve this question edited Mar 12 at 12:02 jonrsharpe 122k30 gold badges268 silver badges476 bronze badges asked Mar 12 at 11:58 ng.newbieng.newbie 3,2706 gold badges32 silver badges71 bronze badges 2
  • 3 Why would you want to avoid that?! – jonrsharpe Commented Mar 12 at 12:02
  • @jonrsharpe My project has many subprojects with separate pyptoject.toml files. I need the same venv for multiple projects. – ng.newbie Commented Mar 12 at 12:11
Add a comment  | 

1 Answer 1

Reset to default 1

You can try to tell poetry explicitely to use the existing virtual environment.

First run:

poetry env info

This returns sth like:

Virtualenv
Path: /Users/youruser/Library/Caches/pypoetry/virtualenvs/yourproject
Python: /Users/youruser/Library/Caches/pypoetry/virtualenvs/yourproject/bin/python

In your new machine run poetry by (use the given Python path!):

poetry env use /Users/youruser/Library/Caches/pypoetry/virtualenvs/projecta-3.10/bin/python

This should run the Python in the local virtualenv folder.

Don't use poetry or pip/pipx! Use uv!

My actual answer would be not to use poetry but to use uv instead. uv is 100x faster than pip and also significantly faster than poetry. The only point is - it is written in Rust. But it is super fast. And you have full control.

I don't know exactly what the structure of your project looks like - but I guess uv will give you much more control. And it installs everything into a local .venv folder, when activated correctly. (uv run python 3.12 e.g.).

And if you provide the .venv folder, I am sure it won't re-install things again.

However, if you change your Operating System, it is forced to reinstall. Because you need other binaries than the installed ones.

本文标签: pythonHow can I reuse the same virtualenv in a different projectStack Overflow