I use Pycharm, and whenever I move a project to another folder, it says "invalid python interpreter selected for the project". I think it happens because the path to venv has changed.
我使用的是PyCharm,每当我将一个项目移动到另一个文件夹时,它都会显示“为该项目选择了无效的Python解释器”。我认为这是因为通向venv的道路改变了。
I tried Configure Python Interpreter > Add Interpreter > Select "Existing Environment" with the new path to venv. I was expecting this to work, but after I click OK, it says "Updating interpreter path" for a moment, and nothing changes. I tried even checking "make available to all projects".
我尝试使用venv的新路径来配置Python解释器>添加解释器>选择“现有环境”。我本以为这会起作用,但在我单击OK之后,它显示了片刻的“正在更新解释器路径”,什么都没有改变。我甚至试着勾选了“对所有项目都可用”。
I also tried some of stack overflow answers, but couldn't make it. How can I fix this?
我也尝试了一些堆栈溢出的答案,但做不到。我怎么才能解决这个问题呢?
Error:Cannot run program "C:\Users\aksha\Pycharm\Digital Clock\venv\Scripts\python.exe" (in directory "C:\Users\aksha\Pycharm\60 Python Projects\Digital Clock"): CreateProcess error=2, The system cannot find the file specified
更多回答
Virtualenv has hardcoded path inside the bin/activate
file, which will fail when you move the virtualenv.
Virtualenv在bin/active文件中具有硬编码路径,当您移动Virtualenv时,该路径将失败。
One way is to recreate your virtualenv. Another way is to open the file bin/activate
and find this line VIRTUAL_ENV='/private/tmp/test2/.venv'
and replace it with your new virtualenv path.
一种方法是重新创建您的虚拟环境。另一种方法是打开文件bin/Activate并找到VIRTUAL_ENV=‘/PRIVATE/tMP/Test2/.venv’行,并将其替换为新的Virtualenv路径。
My virtualenv is created at /tmp/test2/.venv
for reference.
我的Virtualenv在/tmp/est2/.venv中创建,以供参考。
@thuyein's answer did work for me. However, you can also find references to VIRTUAL_ENV in: activate.bat, activate.fish, activate.nu. I updated all of those, then updated the path to interpreter in interpreter's settings as well.
@thouyein的回答对我来说很管用。但是,您还可以在以下位置找到对VIRTUAL_ENV的引用:actiate.bat、actiate.Fish、actiate.nu。我更新了所有这些,然后在解释器的设置中也更新了解释器的路径。
In settings/Project:[your_project_name]/Python Interpreter the gear icon next to Python Interpreter's path contains 'Show all' option. These are all interpreters that Pycharm found on your machine. The paths that got messed up are highlighted in red and marked as [Invalid]. Choose the original path of your project's interpreter and just update it (there's an Edit button at the top of the list) - then you'll be able to set it as current interpreter.
在设置/项目:[YOUR_PROJECT_NAME]/Python解释器中,Python解释器路径旁边的齿轮图标包含‘Show All’选项。这些都是PyCharm在您的机器上找到的解释器。乱七八糟的路径以红色突出显示,并标记为[无效]。选择项目解释器的原始路径,只需更新它(列表顶部有一个编辑按钮)-然后您就可以将其设置为当前解释器。
For me, PyCharm did not have permissions to read /usr/local
due to its confinement. I uninstalled it, then installed it as:
对我来说,由于受到限制,PyCharm没有读取/usr/local的权限。我卸载了它,然后将其安装为:
sudo snap install pycharm-professional --classic
This gave it the required permissions, following which the interpreter error did not reoccur. Following this, create a launcher entry for it.
这为它提供了所需的权限,此后解释器错误不会再次发生。接下来,为其创建一个Launcher条目。
For flatpak
, consider this answer.
对于Flat Pack,请考虑以下答案。
Steps are as follows.
具体步骤如下。
- Open Pycharm
- On extrem right bottom, click on Python version (for example 3.11)
- Select Interpreter Settings
- A new window will popup where select the project (project:YOUR_PROJECT_NAME)
- From right hand side window select python.exe and click on Ok
it should resolve this issue, I've just sorted out following these steps.
它应该可以解决这个问题,我只是按照以下步骤进行了整理。
更多回答
Where do I find those files, and Do I get same error if I shift to Conda Environment!
我在哪里可以找到这些文件,如果我转到Conda环境,我会得到相同的错误吗?
Based on your error message, your virtualenv is here. C:\Users\aksha\Pycharm\Digital Clock\venv
. So open that directory, and inside bin/
folder, you will see activate
file.
根据您的错误消息,您的Virtualenv到了。C:\USERS\AKSHA\PYCharm\Digital Clock\venv。因此,打开该目录,在bin/文件夹中,您将看到激活文件。
Can you list down which is your old path, and which is your new path in your question?
你能在你的问题中列出哪条是你的旧路径,哪条是你的新路径吗?
This is my old path VIRTUAL_ENV="C:\Users\aksha\Pycharm\Digital Clock\venv"
and following one is new VIRTUAL_ENV="C:\Users\aksha\Pycharm\60 Python Projects\Digital Clock\venv"
这是我的旧路径VIRTUAL_ENV=“C:\USERS\AKSHA\PYCharm\Digital Clock\venv”,后面一个是新路径VIRTUAL_ENV=“C:\USERS\AKSHA\PYCharm\60 Python Projects\Digital Clock\venv”
It looks like your error is from your old path. Python cannot find can't open file 'C:\Users\aksha\Pycharm\Digital Clock\digitalClock.py'
this file. So this probably has to do with the way you are executing your python file.
看起来你的错误来自于你的旧道路。Python找不到无法打开此文件的文件‘C:\USERS\AKSHA\PyCharm\Digital Clock\DigitalClock.py’。因此,这可能与您执行python文件的方式有关。
我是一名优秀的程序员,十分优秀!