【记】Windows下pip安装步骤、使用以及遇到的问题
安装
1. 地址:pip · PyPI 注意选择tar.gz压缩包
2. 解压下载的压缩包至工作目录下,打开Windows cmd,运行命令进入解压后的pip目录,在该目录下执行 python setup.py install
如果没有 setuptools 模块需要先安装这个模块:
(1).下载setuptools包:https://pypi.python.org/pypi/setuptools
(2).解压setuptools包
(3).编译setuptools :python setup.py install
(4).开始执行setuptools安装:python setup.py install
我在运行 python setup.py install 的时候遇到了一个问题,报错:ValueError: ZIP does not support timestamps before 1980
这是由于安装文件中,包含了一些没有修改日期的文件,被系统默认为1970年,这时候只需要把所有文件的修改日期修改到1980年以后即可
博客:(11条消息) 【记】ValueError: ZIP does not support timestamps before 1980_Cluic's blog-CSDN博客 提供了一个批量修改文件日期的脚本程序
import os
import time
# 修改文件的【修改日期】
def set_file_time(filename, updatetime='now', access_time='now'):
filename = os.path.abspath(filename)
if updatetime == 'now':
new_updatetime = time.time()
else:
new_updatetime = time.mktime(time.strptime(updatetime, "%Y-%m-%d %H:%M:%S"))
if access_time == 'now':
new_access_time = time.time()
else:
new_access_time = time.mktime(time.strptime(access_time, "%Y-%m-%d %H:%M:%S"))
os.utime(filename, (new_access_time, new_updatetime))
# 修改一个文件夹内所有文件的【修改日期】
def set_all(path):
for i in os.listdir(path):
file = os.path.realpath(os.path.join(path, i))
if os.path.isfile(file):
set_file_time(file)
elif os.path.isdir(file):
set_all(file)
if __name__ == '__main__':
path = r"C:\Users\Administrator\Downloads\pip-21.3.1" # 这里更换为你要修改的文件夹
set_all(path) # 修改以上文件夹内所有文件的日期
再次运行 python setup.py install
3.将python安装目录的Scripts文件夹添加到系统变量中
换源
下在文件管理器的地址栏输入 %APPDATA% ,进入 C:\Users\USERNAME\AppData\Roaming 文件夹内。找到 pip 文件夹,没有就新建一个,打开或新建 pip.ini ,输入以下内容。
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
上面用的是T大的源,也可以使用以下的源替换。
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:https://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/https://pypi.hustunique.com/)
使用
使用pip安装第三方包后,pycharm 中仍旧不能 import
我的方法:重新建项目,创建的时候勾选“inherit global site-packages”,然后点击“create”。因为此时你的项目是用的电脑上 python 的 site-packages ,所以只要你在 python 终端安装了的包,你的项目都可以使用
其余方法可见:使用pip安装第三方包后,pycharm中仍旧不能import - SaidYan - 博客园 (cnblogs.com)