简体   繁体   English

当我尝试在命令提示符中使用 pip 时遇到致命的 Python 错误

[英]Encountering Fatal Python error when I try to use pip in command prompt

I am a new programmer who is trying to follow this tutorial about pip .我是一名新程序员,正在尝试遵循有关 pip 的教程

In the tutorial, you are asked to go into command prompt and type 'pip'.在本教程中,您被要求将 go 进入命令提示符并键入“pip”。 You are supposed to get a list of general options and commands.你应该得到一个通用选项和命令的列表。 However, when I type pip in my command prompt, I get this instead:但是,当我在命令提示符中键入 pip 时,我得到了这个:

C:\Users\myusername>pip
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'C:\Users\myusername\AppData\Local\Programs\Python\Python310\python.exe'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = 'C:\\Users\\myusername\\AppData\\Local\\Programs\\Python\\Python310\\python.exe'
  sys.base_prefix = ''
  sys.base_exec_prefix = ''
  sys.platlibdir = 'lib'
  sys.executable = 'C:\\Users\\myusername\\AppData\\Local\\Programs\\Python\\Python310\\python.exe'
  sys.prefix = ''
  sys.exec_prefix = ''
  sys.path = [
    'C:\\Users\\myusername\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip',
    '.\\DLLs',
    '.\\lib',
    'C:\\Users\\myusername\\AppData\\Local\\Programs\\Python\\Python310',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007590 (most recent call first):
  <no Python frame>

(I am using Windows 10 and Python 3.10.4) (我正在使用 Windows 10 和 Python 3.10.4)

I do not know what this means.我不知道这是什么意思。 This is not addressed in the video.视频中没有解决这个问题。 This happens whenever I do anything pip-related in the command prompt.每当我在命令提示符下执行任何与 pip 相关的操作时,都会发生这种情况。 I am going to reference this error a lot, so let's call it "The Error."我会经常提到这个错误,所以我们称它为“错误”。

Here is how I have tried to resolve this problem:以下是我尝试解决此问题的方法:

  1. Running command prompt as administrator.以管理员身份运行命令提示符。 When I type "pip", this returns The Error.当我输入“pip”时,这将返回错误。
  2. Downloading get-pip.py , trying to install it via command prompt with python get-pip.py .下载get-pip.py ,尝试使用python get-pip.py通过命令提示符安装它。 This returns The Error.这将返回错误。
  3. Updating my version of Python.更新我的 Python 版本。 I updated the version of Python I have when I encountered this error, making sure that the "Install pip" and "add Python to environment variables" checkboxes were ticked.当我遇到此错误时,我更新了 Python 的版本,确保勾选了“安装 pip”和“将 Python 添加到环境变量”复选框。 Updating Python did not fix the problem.更新 Python 并没有解决问题。
  4. executing py -3 -m ensurepip and py -m ensurepip --upgrade in the command prompt.在命令提示符下执行py -3 -m ensurepippy -m ensurepip --upgrade This returns The Error.这将返回错误。
  5. Checking that pip is installed in the Scripts folder in Python.检查 pip 是否安装在 Python 的 Scripts 文件夹中。 It is:这是:

Click here to see my image点击这里查看我的图片

  1. in command prompt, changing the directory to C:\Users\myusername\AppData\Local\Programs\Python\Python310\Scripts and trying pip --version and pip install camelcase from there.在命令提示符下,将目录更改为C:\Users\myusername\AppData\Local\Programs\Python\Python310\Scripts并尝试pip --versionpip install camelcase This returns The Error.这将返回错误。 (camelcase is not part of my project, I tried it purely as an example.) (camelcase 不是我项目的一部分,我只是作为示例尝试过。)
  2. Trying a non-pip related Python command in the command prompt.在命令提示符下尝试与 pip 无关的 Python 命令。 python --version returns Python 3.10.4 , this works as expected. python --version返回Python 3.10.4 ,这按预期工作。
  3. Following this Stack Overflow post from someone experiencing the same error.遇到同样错误的人的这篇 Stack Overflow 帖子之后。 . . This is beyond my understanding, and appears to be about Django.这超出了我的理解,似乎与 Django 有关。 I am not doing anything with Django.我没有对 Django 做任何事情。 I just want to use pip.我只想使用 pip。 The one piece of information I gleaned from this is this quote from a python developer:我从中收集到的一条信息是来自 python 开发人员的这句话:
This is not a Python bug, this is a symptom of setting PYTHONHOME and/or PYTHONPATH when they’re not needed. In nearly all cases you don’t need to set either of them;

In the case of PYTHONHOME it’s almost always a mistake to set.

This does not apply to my case, because my PYTHONHOME and PYTHONPATH are not set.这不适用于我的情况,因为我的 PYTHONHOME 和 PYTHONPATH 没有设置。 The commands unset PYTHONPATH and unset PYTHONHOME return 'unset' is not recognized as an internal or external command, operable program or batch file.命令unset PYTHONPATHunset PYTHONHOME return 'unset' is not recognized as an internal or external command, operable program or batch file.

I have no idea what's going on and I am confused.我不知道发生了什么,我很困惑。 All I want to do is go into the command prompt, type pip and see the list of commands that is supposed to come up.我想做的只是 go 进入命令提示符,输入pip并查看应该出现的命令列表。 I also want to be able to install python modules using pip.我还希望能够使用 pip 安装 python 模块。 These seem like basic things that should automatically work, yet for some reason I am encountering a problem that is out of my depth.这些似乎是应该自动工作的基本事情,但由于某种原因,我遇到了一个超出我深度的问题。

I am not trying to do anything fancy.我不想做任何花哨的事情。 I am a basic user who has been learning basic Python for less than a month, with no prior coding experience.我是一个基础用户,学习基础Python不到一个月,之前没有任何编码经验。 How can I overcome this error so I can successfully use pip?如何克服此错误,以便成功使用 pip? Please keep my level of understanding in mind when you answer my question.当您回答我的问题时,请记住我的理解水平。 Thank you!谢谢!

The answer was to uninstall and reinstall python, this time telling it to set environment variables.答案是卸载并重新安装 python,这一次告诉它设置环境变量。 That did the trick.那成功了。

Thanks, I had the same problem and reinstallation of python solved my problem.谢谢,我遇到了同样的问题,重新安装 python 解决了我的问题。

暂无
暂无

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

相关问题 如何在命令提示符下安装 pip? “启动器中的致命错误” - how do I pip install on the command prompt? "fatal error in launcher" 当我尝试向python中的多个人发送电子邮件时遇到错误 - Encountering an error when I try to send an email to multiple people in python 使用 anaconda 提示一切正常,但是当我尝试使用 git bash 并使用 pip 或 sudo: command not found - Using anaconda prompt everything works fine but when I try to use git bash and use either pip or sudo: command not found 当我尝试通过 pip 安装 mysqlclient 时,仅允许在 C99 模式下遇到“for”循环初始声明错误 - encountering ‘for’ loop initial declarations are only allowed in C99 mode error when I try to install mysqlclient via pip 当我尝试在 Mac OSX 上使用 pip 时,Python 不工作(ImportError) - Python not working (ImportError) when I try to use pip on Mac OSX 尝试升级pip时出现致命的Python错误 - Fatal Python error when attempting to upgrade pip 在命令行中运行 python 命令 pip -list 显示致命错误 - Running python command pip -list in command line show Fatal error 为什么在conda环境下使用pip命令python3.6会一直提示错误? - Why use the pip command in the conda environment python3.6 will always prompt error? Python 3.7-在命令提示符下执行 pip install Jupyter 时出现 SSL 证书错误 - Python 3.7- SSL certificate error when excuting pip install Jupyter on command prompt 当我尝试使用 pip 安装 python 模块时,会导致错误。 我该如何解决? - When I try to install python module using pip, it causes error. How can I fix it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM