简体   繁体   English

python中如何导出虚拟环境设置

[英]How to export the virtual environment settings in python

I am new to python and pycharm tool.我是 python 和 pycharm 工具的新手。 I have created a project and checked in Git hub.我创建了一个项目并签入了 Git 中心。 Now one of my friend pulled the changes and tried to run and he encountered with an error message stating "No interpreters found".现在我的一个朋友提取了更改并尝试运行,他遇到了一条错误消息,指出“找不到解释器”。 When i revalidated the project structure i found that i have 'venv' folder in my project but the person who pulled the changes dosent have it.当我重新验证项目结构时,我发现我的项目中有“venv”文件夹,但是拉取更改的人已经拥有它。

Can you please help me on this.你能帮我解决这个问题吗?

Thanks in Advance!提前致谢!

PS: I am using Windows OS PS:我使用的是 Windows 操作系统

Usually, you don't check in your venv folder.通常,您不会签入您的 venv 文件夹。

Save the output of pip freeze in a file called requirements.txt and check that into your repo.pip freeze的 output 保存在名为requirements.txt的文件中,并将其签入您的存储库。

Once your friend gets the full code, they can install the dependencies using pip install -r requirements.txt一旦您的朋友获得完整代码,他们就可以使用pip install -r requirements.txt安装依赖项

As you've said you're new to Python, I'll try to explain how things work in Python projects.正如您所说的,您是 Python 的新手,我将尝试解释 Python 项目中的工作原理。

Steps to do setup on your another machine.在另一台机器上进行设置的步骤。

  1. Export all the installed and used packages for your project using pip freeze and write them to a text file which contains library names and versions.使用pip freeze导出项目的所有已安装和使用的包,并将它们写入包含库名称和版本的文本文件。 Add this file to your project.将此文件添加到您的项目中。 Convention is to name it as requirements.txt .约定是将其命名为requirements.txt Refer this https://pip.pypa.io/en/stable/reference/pip_freeze/参考这个https://pip.pypa.io/en/stable/reference/pip_freeze/
  2. Create a virtual environment in another machine with same python version.在另一台具有相同 python 版本的机器上创建虚拟环境。
  3. Activate the environment and install the libraries again using the file you've exported initially.激活环境并使用您最初导出的文件再次安装库。

Note: It's not suggested to have venv folder which contains all your packages inside your project directory itself.注意:建议在项目目录本身中包含包含所有包的 venv 文件夹。 You may have to add the folder to .gitignore just for this purpose.为此,您可能必须将该文件夹添加到.gitignore

You might want to take a look at .idea folder in project directory.您可能想查看项目目录中的.idea文件夹。 But I don't think that would be much useful.但我认为这不会有多大用处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM