简体   繁体   English

更改 Python 解释器/编译器的路径

[英]Change Path of Python Interpreter/Compiler

I have a Folder (python311) where I have all of the Python Components stored ("Lib", "Scripts", "python.exe"...) which is on this Path: D:\python311.我有一个文件夹 (python311),其中存储了所有 Python 组件(“Lib”、“Scripts”、“python.exe”...),该文件夹位于此路径中:D:\python311。 Now I want to move this Folder (python311) into another Folder (Code) -> Path: D:\Code\python311.现在我想将这个文件夹 (python311) 移动到另一个文件夹 (Code) -> Path: D:\Code\python311。 Using VS Code it lets me choose the Interpreter which is fine, but when I want to intsll new modules with pip, it does not work.使用 VS Code 它可以让我选择很好的解释器,但是当我想使用 pip 插入新模块时,它不起作用。 It tries to create an process between the Interpreter of the old Path (D:\python311\python.exe), which is no longer existent, and the new Path where pip is stored (D:\Code\python311\Scripts\pip.exe).它试图在旧路径 (D:\python311\python.exe) 的解释器(不再存在)和存储 pip 的新路径(D:\Code\python311\Scripts\pip.exe)之间创建一个进程。可执行程序)。

Solutions that I can think of would be for example reinstalling Python. I don't know if it can be solved through environment variables but it won't work because I store the Python Components on an external Drive.我能想到的解决方案是例如重新安装 Python。我不知道它是否可以通过环境变量解决,但它不会工作,因为我将 Python 组件存储在外部驱动器上。

You can solve it using environment variables even if it is on an external drive.即使它在外部驱动器上,您也可以使用环境变量来解决它。

You will need to remove the old entry in the PATH variable and add the new entry (the new python path) or edit the old entry to include the new path.您需要删除PATH变量中的旧条目并添加新条目(新的 python 路径)或编辑旧条目以包含新路径。

Change path in environment variables -> Path更改环境变量中的路径 -> 路径

Furthermore, I have all my Pythons installed in same location:此外,我将所有 Python 安装在同一位置:

PS C:\Python> ls

    Directory: C:\Python

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----           22.8.2022    11.23                p105_32
d----           15.8.2022    17.12                p105_64

When I want to use different versions I create a new virtual environment Virtualenvwrapper .当我想使用不同的版本时,我创建了一个新的虚拟环境Virtualenvwrapper

mkvirtualenv envname -p C:/Python/p105_32
workon envname

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

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