更改Virtualenv文件夹名称后无法执行PIP
因此,以前,我将我的虚拟环境命名为“测试”。之后,我将其更改为“ 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您绝对不应重命名虚拟Python环境。创建虚拟环境时,该路径在多个位置进行了硬编码(例如,请参见
scripts/activate*
脚本)。您可以尝试替换所有文件中的硬编码路径,但是我不确定它有多好,以及(python/venv)版本之间是否有所改变。
最好的办法就是删除旧的虚拟环境并创建一个新的环境。
一样简单。
sumpliont.txt
文件,则与:py -3.10 -m venv new_env
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:py -3.10 -m venv new_env
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 runpip 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.