简体   繁体   English

Pipenv:git 克隆后在新计算机上激活虚拟环境

[英]Pipenv: Activate virtual environment on new computer after git clone

I copied a repo containing a Python Django project from my old computer to my new one via git clone .我通过git clone从我的旧计算机复制了一个包含 Python Django 项目的存储库到我的新计算机。 I manage my dependecies in the project via pipenv.我通过 pipenv 管理我在项目中的依赖。

After successfully cloning my repo I wanted to start working on the new computer and tried to select the relevant python interpreter for my project in VS Code.成功克隆我的仓库后,我想开始在新计算机上工作,并尝试在 VS Code 中为我的项目使用 select 相关的 python 解释器。 However, the path was not on the list.但是,路径不在列表中。

So first I tried the command pipenv --venv which gave me the feedback: No virtualenv has been created for this project所以首先我尝试了命令pipenv --venv它给了我反馈: No virtualenv has been created for this project

So I thought I might need to activate the virtual environment first, before being able to select it in VS Studio code.所以我想我可能需要先激活虚拟环境,然后才能在 VS Studio 代码中对其进行 select 。 So i ran pipenv shell in the root directory of my project.所以我在项目的根目录中运行了pipenv shell

However this seem to have created a new virtual environment: Creating a virtualenv for this project… Pipfile: C:\path\to\my\cloned\project\Pipfile然而,这似乎已经创建了一个新的虚拟环境: Creating a virtualenv for this project… Pipfile: C:\path\to\my\cloned\project\Pipfile

My questions: 1.) Is this the correct way to activate a pipenv virtualenvironment on a new computer after copying the project via git clone?我的问题: 1.) 在通过 git 克隆复制项目后,这是在新计算机上激活 pipenv 虚拟环境的正确方法吗? And if not,... 2.1) Does the way I did it cause any problems, which I should be aware of?如果没有,... 2.1) 我这样做的方式是否会导致任何问题,我应该注意这些问题? 2.2) What would be the correct procedure to activate my virtual enviroment on a new computer? 2.2) 在新计算机上激活我的虚拟环境的正确程序是什么?

In general an environment image probably shouldn't be copied to github.一般来说,环境图像可能不应该被复制到 github。 You'll get a bunch of unneeded files which clogs your repo.你会得到一堆不需要的文件,这些文件会阻塞你的 repo。

Instead you should create a requirements.txt from your existing environment pip freeze > requirements.txt and commit that file.相反,您应该从现有环境pip freeze > requirements.txt requirements.txt提交该文件。

Then when someone else clones your repo they can set up a new virtual environment using any tool they want and run python -m pip install -r requirements.txt然后,当其他人克隆您的存储库时,他们可以使用他们想要的任何工具设置新的虚拟环境并运行python -m pip install -r requirements.txt

That is, requirements.txt is like a recipe for how to create your environment.也就是说, requirements.txt就像是如何创建环境的秘诀。 By providing the recipe users can use it any way they want.通过提供配方,用户可以以任何他们想要的方式使用它。

use:利用:

pipenv install

It worked on Ubuntu, should work also on a mac.它适用于 Ubuntu,也应该适用于 mac。 I tried on a windows, it triggered some errors.我试过 windows,它触发了一些错误。

"If you download a source repository for a project that uses Pipenv for package management, all you need to do is unpack the contents of the repository into a directory and run pipenv install (no package names needed). Pipenv will read the Pipfile and Pipfile.lock files for the project, create the virtual environment, and install all of the dependencies as needed." “如果您为使用 Pipenv 进行 package 管理的项目下载源存储库,您所需要做的就是将存储库的内容解压缩到一个目录并运行 pipenv 安装(不需要 package 名称)。 Pipenv 将读取 Pipfile 和 Pipfile .lock 文件,创建虚拟环境,并根据需要安装所有依赖项。” https://www.infoworld.com/article/3561758/how-to-manage-python-projects-with-pipenv.html https://www.infoworld.com/article/3561758/how-to-manage-python-projects-with-pipenv.html

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

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