简体   繁体   English

pip 在错误的文件夹中查找

[英]pip looking in wrong folder

My issue requires some backstory.我的问题需要一些背景故事。

I was having some troubles with pip, so I reinstalled Python.我在使用 pip 时遇到了一些问题,所以我重新安装了 Python。 After the reinstall pip began to work, but Pycharm, my IDE, could no longer find Python.重装后pip开始工作了,但是Pycharm,我的IDE,再也找不到ZA237417171936B69了When I reinstalled Python it created a new folder for itself (Python310), but Pycharm kept looking in the old folder (Python39).当我重新安装 Python 时,它为自己创建了一个新文件夹(Python310),但 Pycharm 一直在寻找旧文件夹(Python39)。 I couldn't figure out how to get Pycharm to look in the new folder.我不知道如何让 Pycharm 查看新文件夹。 Even deleting and reinstalling it did nothing.即使删除并重新安装它也无济于事。

So, I renamed Python310 to Python39 and changed the PATH.因此,我将 Python310 重命名为 Python39 并更改了 PATH。 Now Pycharm can find Python.现在Pycharm可以找到Python。 But pip has developed a new and exciting error.但是 pip 出现了一个新的令人兴奋的错误。 When I try to use it I get the following message:当我尝试使用它时,我收到以下消息:

Fatal error in launcher: Unable to create process using '"C:\Users\user\AppData\Local\Programs\Python\Python310\python.exe" "C:\Users\user\AppData\Local\Programs\Python\Python39\Scripts\pip.exe" install numpy': The system cannot find the file specified.

If I read this correctly pip is still trying to look in Python310.如果我正确阅读此内容,pip 仍在尝试查看 Python310。 Would you please tell me what I need to do to get pip to looking in the right place?你能告诉我我需要做什么才能让 pip 找到正确的位置吗?

So, to start.所以,开始吧。 You don't fix this by renaming the folder where the interpreter resides.您不能通过重命名解释器所在的文件夹来解决此问题。 Even if that worked, it's not a fix.即使这有效,也不是解决办法。 The name will say one thing, but it's actual version, compatible libraries, and anything else tied to the version number would be incorrect.名称会说明一件事,但它的实际版本、兼容库以及与版本号相关的任何其他内容都是不正确的。

If you take a close look at the error message from pip, it tells us what's wrong.如果您仔细查看来自 pip 的错误消息,它会告诉我们出了什么问题。

Fatal error in launcher: Unable to create process using '"C:\Users\user\AppData\Local\Programs\Python\Python310\python.exe" "C:\Users\user\AppData\Local\Programs\Python\Python39\Scripts\pip.exe" install numpy': The system cannot find the file specified.启动器中的致命错误:无法使用 '"C:\Users\user\AppData\Local\Programs\Python\Python310\python.exe" "C:\Users\user\AppData\Local\Programs\Python\Python39 创建进程\Scripts\pip.exe" install numpy': 系统找不到指定的文件。

You renamed the directory, so your IDE can find it, but pip and everything else using the Python interpreter is still configured to look in the Python39 directory to find it.你重命名了目录,所以你的 IDE 可以找到它,但是 pip 和其他所有使用 Python 解释器的东西仍然配置为在 Python 目录中查找它。

The problem you are having is that your IDE, PyCharm, needs to be configured for your project.您遇到的问题是您的 IDE、PyCharm 需要为您的项目进行配置。 You have to tell it where the Python interpreter is.你必须告诉它 Python 解释器在哪里。 The simple solution, you can rename your your Python folder back to it's original state, and add it to your project.简单的解决方案,您可以将 Python 文件夹重命名回原来的 state,然后将其添加到您的项目中。

  1. Press Ctrl+Alt+S to open the project Settings/Preferences and go to Project |按 Ctrl+Alt+S 打开项目 Settings/Preferences 和 go 到 Project | Python Interpreter. Python 口译员。 Click the Add Interpreter link next to the list of the available interpreters.单击可用解释器列表旁边的添加解释器链接。

  2. Expand the list of the available interpreters and click the Show All link.展开可用解释器的列表并单击 Show All 链接。

  3. Select the target interpreter. Select 目标解释器。 In your case, look for the one with this file path: "C:\Users\user\AppData\Local\Programs\Python\Python310\python.exe"在您的情况下,查找具有以下文件路径的文件:“C:\Users\user\AppData\Local\Programs\Python\Python310\python.exe”

I would recommend going one step futher and create an interpreter in a virtual environment.我建议更进一步,在虚拟环境中创建一个解释器。 Especially if you are interested in Python beyond a very casual hobby.特别是如果您对 Python 感兴趣,而不仅仅是一个非常随意的爱好。 They are unavoidable.它们是不可避免的。

This link is a good source and can help you with this:此链接是一个很好的来源,可以帮助您:

https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#interpreter https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#interpreter

There, you will find screenshots that follow the steps I listed above.在那里,您会找到按照我上面列出的步骤的屏幕截图。 There are also detailed instructions on how to create and add a new interpreter in a virtual environment.还有关于如何在虚拟环境中创建和添加新解释器的详细说明。 The relevant headings are as follows:相关标题如下:

  • Configure a Python interpreter配置一个Python解释器
  • Python interpreters in PyCharm Python PyCharm 中的解释器
  • Setting an existing Python interpreter设置现有的 Python 解释器
  • Creating a new Python interpreter创建一个新的 Python 解释器

The rest of the content is great as well, and may help answer questions you didn't know you had.内容的 rest 也很棒,可能有助于回答您不知道的问题。

try to uninstall all of the existing python versions.尝试卸载所有现有的 python 版本。 and install it again.并再次安装。 using any of application allow you to delete most of files, so to prevent error when re-install.使用任何应用程序都可以删除大部分文件,以防止重新安装时出错。

Option 1:选项1:

delete and reinstall again.删除并重新安装。 and then when creating a project it should prompt you to pick a basic interpreter, choose python310 or whatever version you're using.然后在创建项目时,它应该提示您选择基本解释器,选择 python310 或您正在使用的任何版本。

Option 2:选项 2:

use a different IDE.使用不同的 IDE。

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

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