持续更新,常用命令就在这里找找吧
Centos下进入python虚拟环境venv
centos自带虚拟环境工具,不用安装
创建虚拟环境
python3 -m venv venv(自定义名称)
进入虚拟环境
source venv/bin/activate
pip常用命令
pip3 install pytest -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
pip3 freeze > requirements.txt # 生成txt包目录
pip3 install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ # 指定源安装 可能会报错
pip install -r requirements.txt --trusted-host mirrors.aliyun.com # 信任安装源
pip install package_name --trusted-host mirrors.aliyun.com
pip download 包名 -i https://pypi.tuna.tsinghua.edu.cn/simple -d 存放目录 # 下载包
python -m pip install --upgrade pip #升级pip版本
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U #从国内镜像升级,首选清华镜像
pip list 查看所有安装的包
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple #设置清华镜像为全局镜像
pip show package_name # package_name为包名 查看安装包的详细信息
pip install --upgrade package_name #package_name为包名 更新指定的包
pip install package_name #这里的package_name是要安装的第三方库名
pip install package_name -i http://mirrors.aliyun.com/pypi/simple/ # 指定国内环境安装
pip install package_name=版本号 #安装指定版本号
pip uninstall package_name #这里的package_name是要卸载的第三方库名
pip install C:\Users\Administrator\Downloads\pymssql-2.2.2-cp38-cp38-win_amd64.whl # 本地安装包 后面是包所在路径和包名
安装包的时候速度很慢可以指定以下安装源
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/
百度云:https://mirror.baidu.com/pypi/simple/
华为云:https://mirrors.huaweicloud.com/repository/pypi/simple/
腾讯云:https://mirrors.cloud.tencent.com/pypi/simple/
pip install 遇到SSL问题
临时解决
pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org lxml(包名)
or
pip install keras -i http://pypi.douban.com/simple --trusted-host pypi.douban.com(其中的keras是你需要下载的,根据自己需求自行更改)
试试 将系统时间更新一下 ntp 服务
linux 中将python程序后台运行
# 创建一个Python脚本,例如 my_script.py,其中包含你要运行的Python代码
# 在终端中,使用以下命令将Python脚本作为后台程序运行
nohup python3 my_script.py &
#这将启动你的Python程序并将其放入后台运行。
# nohup 命令用于在程序运行时防止终端关闭后程序被终止。& 符号将程序放入后台运行。
# 如何将上述的python程序关闭
# 使用 ps 命令查找进程ID(PID):
ps aux | grep my_script.py
# 使用 kill 命令终止进程:
kill [PID]
python-- .gitignore文件
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/