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

我是python和pycharm工具的新手。我创建了一个项目,并在Git Hub中签入。现在,我的一位朋友撤消了更改并尝试运行,他遇到了一条错误消息,指出“未找到解释器”。当我重新验证项目结构时,我发现我的项目中有'venv'文件夹,但是进行更改的人拥有它。

你能帮我这个忙吗?

提前致谢!

PS:我正在使用Windows OS

评论
yut
yut

通常,您不检入venv文件夹。

Save the output of pip freeze in a file called requirements.txt and check that into your repo.

Once your friend gets the full code, they can install the dependencies using pip install -r requirements.txt

点赞
评论
厮守
厮守

正如您所说的那样,您是Python的新手,我将尝试解释Python项目中的工作原理。

在另一台计算机上进行设置的步骤。

  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. Add this file to your project. Convention is to name it as requirements.txt. Refer this https://pip.pypa.io/en/stable/reference/pip_freeze/
  2. Create a virtual environment in another machine with same python version.
  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. You may have to add the folder to .gitignore just for this purpose.

点赞
评论