简体   繁体   English

Python中如何将现有的虚拟环境导入新项目?

[英]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.

相关问题 如何使用虚拟环境导出python项目? - How to export python project with virtual environment? 在 Python 中使用虚拟环境导入模块 - Import module with virtual environment in Python 如何更改现有conda虚拟环境的Python版本? - How to change Python version of existing conda virtual environment? 将 python 项目与虚拟环境相关联 - Associating a python project with a virtual environment 用virtualenvwrapper新建虚拟环境时如何选择Python版本? - How to choose Python version when making a new virtual environment with virtualenvwrapper? 无法在Python 2.7.9虚拟环境中导入_winreg - Unable to import _winreg in Python 2.7.9 virtual environment 将现有 python 项目导入 XCode - Import an existing python project to XCode 同时使用python 2和3的项目的虚拟环境? - Virtual environment for a project that uses both python 2 and 3? 批处理可启动python虚拟环境并在项目目录中运行虚拟python - Batch that starts python virtual environment and runs the virtual python in a project dir 如何在不升级2.7的OSX上升级python现有版本的情况下,如何使用python 3安装虚拟环境 - How to install virtual environment with python 3 without upgrading existing version of python on my OSX which is 2.7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM