更改Virtualenv文件夹名称后无法执行PIP

发布于 2025-02-04 06:25:35 字数 297 浏览 1 评论 0原文

因此,以前,我将我的虚拟环境命名为“测试”。之后,我将其更改为“ testt”,然后我再也无法访问pip命令了,它给了我以下错误:

Fatal error in launcher: Unable to create process using '"C:\coding\test\test\Scripts\python.exe"  "C:\coding\test\testt\Scripts\pip.exe" ': The system cannot find the file specified.

如何解决此问题?

So previously I named my virtual environment "test". After that, I changed it to "testt", and after that I can't access pip commands anymore and it gives me the following error:

Fatal error in launcher: Unable to create process using '"C:\coding\test\test\Scripts\python.exe"  "C:\coding\test\testt\Scripts\pip.exe" ': The system cannot find the file specified.

How can I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弄潮 2025-02-11 06:25:35

您绝对不应重命名虚拟Python环境。创建虚拟环境时,该路径在多个位置进行了硬编码(例如,请参见scripts/activate*脚本)。

可以尝试替换所有文件中的硬编码路径,但是我不确定它有多好,以及(python/venv)版本之间是否有所改变。

最好的办法就是删除旧的虚拟环境并创建一个新的环境。

一样简单。

  1. 如果您使用的是sumpliont.txt文件,则与: py -3.10 -m venv new_env
  2. new_env \ scripts \ python.exe -mm pip install -r unigess.txt

(示例命令适用于Windows和Python 3.10,但对于Linux和/或其他Python版本相似)

如果您不使用需求.txt文件,您可以在删除旧的虚拟环境之前运行pip冻结,以查看已安装的模块。

旁注:此方法的优点是您实际上正在验证您的环境是否已有文献记载(即unignts.txt是最新的),并且可以重现它。这也将使将来重复此过程(例如在另一台计算机上)更容易。

You should never rename a virtual Python environment. When creating the virtual environment, the path is hardcoded in several places (see the Scripts/activate* scripts for example).

You could try to replace the hardcoded paths in all files, but I'm not sure how good this works and if this changes between (Python/venv) versions.

Best thing to do is just remove the old virtual environment and create a new one.

If you're using a requirements.txt file, this as as easy as:

  1. py -3.10 -m venv new_env
  2. new_env\Scripts\python.exe -m pip install -r requirements.txt

(example commands are for Windows and Python 3.10, but are similiar for Linux and/or other Python versions)

If you didn't use a requirements.txt file, you could run pip freeze before removing the old virtual environment to see which modules you had installed.

Side note: this method has the advantage that you're actually verifying that your environment is well documented (i.e., the requirements.txt is up-to-date) and that you can reproduce it. This will make it easier to repeat this process in the future (e.g. on another computer) as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文