python
wget https://www.python.org/ftp/python/3.7.3/python-3.7.3-amd64.exe
配置环境变量
将如下目录配置到PATH中即可
- python.exe所在的目录
- python.exe所在的目录下的Scripts
使用国内pypi镜像
方式一:临时使用
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ selenium
pip3 install -i https://mirrors.aliyun.com/pypi/simple/ mysql-connector
方式二:永久使用
for windows
mkdir %APPDATA%\pip
cd %APPDATA%\pip
type nul > pip.ini
echo [global] > pip.ini
echo timeout=6000 >> pip.ini
echo index-url=https://mirrors.aliyun.com/pypi/simple/ >> pip.ini
echo [install] >> pip.ini
echo trusted-host=https://mirrors.aliyun.com >> pip.ini
for linux
将如下内容放到~/.pip/pip.conf文件中即可
[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
问题
C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe: No module named pip
python -m ensurepip
解决办法见 https://blog.csdn.net/weixin_44935307/article/details/127501512
升级 pip: You are using pip version 19.0.3, however version 23.1.2 is available. You should consider upgrading via the ‘python -m pip install –upgrade pip’ command.
# 使用如下
python -m pip install -i https://mirrors.aliyun.com/pypi/simple/ --upgrade pip
# 而非
python -m pip install --upgrade pip
编码
在给一个自定义对象的某字段赋值时做些其它操作
import jsons
class Hello:
code: int
msg: str
def __setattr__(self, name, value):
print('here', name, value)
if name == 'msg':
# 每执行一次,就追加一次
self.__dict__.__setitem__(name, value + " -- updated")
else:
self.__dict__.__setitem__(name, value)
def test_type_hello():
hello = Hello()
# 会导致调用__setattr__
hello.code = 100
# 会导致调用__setattr__
hello.msg = 'abcdef'
assert 'abcdef' in hello.msg
assert '-- updated' in hello.msg
json_data = jsons.dump(hello)
# 会导致调用__setattr__
hello_de = jsons.load(jsons.dump(json_data), Hello)
assert 'abcdef' in hello_de.msg
assert '-- updated' in hello_de.msg
作者:admin 创建时间:2022-04-19 16:17
最后编辑:admin 更新时间:2025-09-19 10:08
最后编辑:admin 更新时间:2025-09-19 10:08