[英]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:我创建了一个 venv,我想在另一个文件中使用它,但由于某种原因它说:
"Python cannot be found"
“找不到 Python”
I installed Python 3.9.2
on Windows 10 and created a venv that worked perfectly in a previous project.我在 Windows 10 上安装了
Python 3.9.2
并创建了一个在之前的项目中完美运行的 venv。 However, I created a new file in the same folder (inside my venv folder) and it's not working.但是,我在同一个文件夹(在我的 venv 文件夹内)创建了一个新文件,但它不工作。 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.我读到了
#.\path\to\venv\bin\activate (also \activate.bat and \python)
,但我没有bin 文件夹,我用bin 替换了Scripts,仍然无法正常工作。 How can I solve this?我该如何解决这个问题?
Side note: the first script runs without issue.旁注:第一个脚本运行没有问题。 Moreover, I installed
Python
in a folder called python39.此外,我在名为
Python
的文件夹中安装了 Python。
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.每个虚拟环境都有自己的 Python 二进制文件(与用于创建此环境的二进制文件的版本匹配),并且可以在其站点目录中拥有自己独立的一组已安装的 Python 包。
(from https://docs.python.org/3.9/library/venv.html ) (来自https://docs.python.org/3.9/library/venv.html )
So at the moment of environment creation, the python binary is copied.所以在环境创建的那一刻,python 二进制文件被复制。 You can't just copy the venv from one place to another and expect the corresponding binary to work.
您不能只是将 venv 从一个地方复制到另一个地方并期望相应的二进制文件能够工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.