简体   繁体   中英

How to import an existing virtual environment to a new project in Python?

I created a venv and I want to use it in another file, but for some reason it says that:

"Python cannot be found"

I installed Python 3.9.2 on Windows 10 and created a venv that worked perfectly in a previous project. However, I created a new file in the same folder (inside my venv folder) and it's not working. How can I activate it?

I read about #.\path\to\venv\bin\activate (also \activate.bat and \python) but I don't have a bin folder, I replaced bin for Scripts, still not working. How can I solve this?

Side note: the first script runs without issue. Moreover, I installed Python in a folder called python39.

Thank you in advance!

Each virtual environment has its own Python binary (which matches the version of the binary that was used to create this environment) and can have its own independent set of installed Python packages in its site directories.

(from https://docs.python.org/3.9/library/venv.html )

So at the moment of environment creation, the python binary is copied. You can't just copy the venv from one place to another and expect the corresponding binary to work.

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