Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

Gray-Ice

个人博客兼个人网站

pip升级失败解决方案

今天使用pip安装模块的时候,提示我pip有新版本了,我就随手升级了一下:

1
pip install --upgrade pip

结果安装失败了。

1
2
3
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问。: 'd:\\virtual env
ironment\\for_django\\scripts\\pip.exe'
Consider using the `--user` option or check the permissions.

然后输入pip,报错:

1
ModuleNotFoundError: No module named 'pip'

啊这,这可怎么办?

那么下面就是解决方法:

首先,输入命令:

1
python -m ensurepip

安装成功:

1
2
3
4
5
6
Requirement already satisfied: setuptools in d:\virtual environment\for_django\lib\site-packages (46.1.
3)
Collecting pip
Installing collected packages: pip
Successfully installed pip-10.0.1

然后,输入pip,提示:

1
ModuleNotFoundError: No module named 'pip._internal.cli'

不急,我们接着输入下一条命令:

1
python -m pip install --upgrade pip

成功:

1
2
3
4
5
Installing collected packages: pip
Found existing installation: pip 10.0.1
Uninstalling pip-10.0.1:
Successfully uninstalled pip-10.0.1
Successfully installed pip-20.1.1

这时输入pip,成功提示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Usage:
pip <command> [options]

Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
config Manage local and global configuration.
search Search PyPI for packages.
cache Inspect and manage pip's wheel cache.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
debug Show information useful for debugging.
help Show help for commands.

General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring environment variables and user
configuration.
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be used up to 3 times
(corresponding to WARNING, ERROR, and CRITICAL logging levels).
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should attempt (default 5
times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe,
(b)ackup, (a)bort.
--trusted-host <hostname> Mark this host or host:port pair as trusted, even though it does not
have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file containing the private
key and the certificate in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine whether a new version of pip
is available for download. Implied with --no-index.
--no-color Suppress colored output
--no-python-version-warning
Silence deprecation warnings for upcoming unsupported Pythons.

pip升级成功~

生成requirements.txt文件失败解决方案

升级成功后,我想生成个requirements.txt文件来记录一下我安装的模块,结果又报错了:

1
2
3
(for_django) D:\use_for_study\None\django123>pip freeze > requirements.txt
WARNING: Could not generate requirement for distribution -ip 20.0.2 (d:\virtual environment\for_django\
lib\site-packages): Parse error at "'-ip==20.'": Expected W:(abcd...)

这时打开我的虚拟环境目录,D:\virtual environment\for_django,进入lib文件夹下的site-packages文件夹,找到一个文件名里含有ip-20的文件夹(若是WARNING里ip==19.则找到文件名里含有ip-19的文件夹),删掉。

然后再次尝试生成文件:

1
(for_django) D:\use_for_study\None\django123>pip freeze >requirements.txt

成功生成requirements.txt文件~

评论



愿火焰指引你