首页 > 解决方案 > 安装 pip python 时出现问题

问题描述

我安装了python 3.7.2仍然没有安装pip,对于pip,安装python的目录中的文件夹脚本中必须有pip.exe,但在我的设备中没有任何内容。

后来我尝试通过运行 get-pip.py 来安装它,但它在命令提示符下抛出异常

命令提示符引发异常:-

Installing collected packages: pip, setuptools, wheel Exception: Traceback (most recent call last):
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\distutils\uti l.py", line 187, in subst_vars return re.sub(r'\$([a-zA-Z_][a-zA-Z_0-9]*)', _subst, s)
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\re.py", line 192, in sub return _compile(pattern, flags).sub(repl, string, count) 
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\distutils\uti l.py", line 184, in _subst return os.environ[var_name]
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\os.py", line 678, in getitem raise KeyError(key) from None KeyError: 'in'

在处理上述异常的过程中,又出现了一个异常:

Traceback (most recent call last):
File "C:\Users\Del$in\AppData\Local\Temp\tmpwzho1r2w\pip.zip\pip_internal\cli \base_command.py", line 179, in main status = self.run(options, args)
File "C:\Users\Del$in\AppData\Local\Temp\tmpwzho1r2w\pip.zip\pip_internal\com mands\install.py", line 393, in run use_user_site=options.use_user_site, 
File "C:\Users\Del$in\AppData\Local\Temp\tmpwzho1r2w\pip.zip\pip_internal\req __init__.py", line 57, in install_given_reqs **kwargs
File "C:\Users\Del$in\AppData\Local\Temp\tmpwzho1r2w\pip.zip\pip_internal\req \req_install.py", line 913, in install use_user_site=use_user_site, pycompile=pycompile,
File "C:\Users\Del$in\AppData\Local\Temp\tmpwzho1r2w\pip.zip\pip_internal\req \req_install.py", line 445, in move_wheel_files warn_script_location=warn_script_location,
File "C:\Users\Del$in\AppData\Local\Temp\tmpwzho1r2w\pip.zip\pip_internal\whe el.py", line 320, in move_wheel_files prefix=prefix,
File "C:\Users\Del$in\AppData\Local\Temp\tmpwzho1r2w\pip.zip\pip_internal\loc ations.py", line 180, in distutils_scheme i.finalize_options()
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\distutils\com mand\install.py", line 307, in finalize_options self.expand_basedirs()
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\distutils\com mand\install.py", line 475, in expand_basedirs self._expand_attrs(['install_base', 'install_platbase', 'root'])
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\distutils\com mand\install.py", line 469, in _expand_attrs val = subst_vars(val, self.config_vars)
File "C:\Users\Del$in\AppData\Local\Programs\Python\Python37\lib\distutils\uti l.py", line 189, in subst_vars raise ValueError("invalid variable '$%s'" % var) ValueError: invalid variable '$'in''

标签: pythonpipcommand-prompt

解决方案


从代码中distutils/utils.py

def subst_vars (s, local_vars):
    """Perform shell/Perl-style variable substitution on 'string'.  Every
    occurrence of '$' followed by a name is considered a variable, and
    variable is substituted by the value found in the 'local_vars'
    dictionary, or in 'os.environ' if it's not in 'local_vars'.
    'os.environ' is first checked/augmented to guarantee that it contains
    certain values: see 'check_environ()'.  Raise ValueError for any
    variables not found in either 'local_vars' or 'os.environ'.
    """

这是利用 bash/Perl 脚本中非常常见的实用程序,您可以在其中使用以下命令替换值$

SOMEPATH='$HOME/somefolder'

echo($SOMEPATH)
# '/path/to/somefolder'

不幸的是,您的用户名模仿了这一点,并且会导致问题,直到它被更改


推荐阅读