下载 python 安装包
地址:https://www.python.org/downloads 选择需要的 python 安装包
PS D:\downloads> dir
目录: D:\downloads
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2021/11/29 9:10 20598784 python-2.7.18.amd64.msi
-a---- 2022/2/12 11:32 19632128 python-2.7.18.msi
-a---- 2021/11/29 9:09 28315928 python-3.10.0-amd64.exe
-a---- 2022/2/7 14:19 27204536 python-3.8.10.exe
-a---- 2022/1/23 8:59 27866224 python-3.8.4-amd64.exe
-a---- 2022/1/21 18:34 1914683 pythonnet-2.5.2.tar.gz
PS D:\downloads>
安装下载的包
注意,开发中常常需要各个版本的 python 安装包,所以建议设置一下安装路径,不需要将 python 加入到环境变量中去(需要的话,可以添加;当然也可以手动添加 %python_home%,以及 %python_home%/Scripts 到 path 中去)。
PS D:\downloads> cd ..\devTools\Python\
PS D:\devTools\Python>
PS D:\devTools\Python> dir
目录: D:\devTools\Python
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2022/2/12 11:35 Python27
d----- 2022/2/12 11:36 Python27-32
d----- 2022/2/12 11:41 Python310
d----- 2022/1/23 9:03 Python38
d----- 2022/2/7 14:21 Python38-32
PS D:\devTools\Python>
配置pip
1. 在 c盘用户下建立 pip 目录
2. 进入 pip 目录,创建文件 pip.ini
3. 编辑 pip.ini,内容如下:
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
查看 pip 配置
PS D:\OtherProjects\action\practice-demo-python> pip config list
global.index-url='https://mirrors.aliyun.com/pypi/simple/'
install.trusted-host='mirrors.aliyun.com'
PS D:\OtherProjects\action\practice-demo-python>
pip list 查看本地所有安装的包
PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python27\Scripts\pip.exe list
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Package Version
---------- -------
pip 19.2.3
setuptools 41.2.0
WARNING: You are using pip version 19.2.3, however version 20.3.4 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
PS D:\OtherProjects\other\python\python_env27>
pip freeze [> file.txt] 导出当前环境安装的所有包
注意:该命令是导出环境,不是项目依赖的包!
PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python27\Scripts\pip.exe freeze
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
# 新环境,还没得???加上 --all 就可以看到了
PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python27\Scripts\pip.exe freeze --all
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
pip==19.2.3
setuptools==41.2.0
PS D:\OtherProjects\other\python\python_env27>
PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python38\Scripts\pip.exe freeze
aliyun-python-sdk-alidns==2.6.29
aliyun-python-sdk-core==2.13.35
asgiref==3.3.4
backports.zoneinfo==0.2.1
cachetools==4.2.2
certifi==2021.5.30
cffi==1.15.0
chardet==4.0.0
coreapi==2.3.3
coreschema==0.0.4
cryptography==36.0.1
Django==3.2.4
djangorestframework==3.13.1
drf-yasg==1.20.0
fuzzywuzzy==0.18.0
google-auth==1.31.0
idna==2.10
inflection==0.5.1
itypes==1.2.0
Jinja2==3.0.3
jmespath==0.10.0
kubernetes==18.20.0b1
MarkupSafe==2.0.1
minio==7.1.0
mysql-connector==2.2.9
oauthlib==3.1.1
packaging==21.3
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
pyparsing==3.0.7
python-dateutil==2.8.1
pythonnet==2.5.2
pytz==2021.1
PyYAML==5.4.1
requests==2.25.1
requests-oauthlib==1.3.0
rsa==4.7.2
ruamel.yaml==0.17.20
ruamel.yaml.clib==0.2.6
six==1.16.0
sqlparse==0.4.1
typing-extensions==3.10.0.0
tzdata==2021.5
uritemplate==4.1.1
urllib3==1.26.5
websocket-client==1.1.0
PS D:\OtherProjects\other\python\python_env27>
包管理 pipreqs
# 安装pipreqs工具
pip install pipreqs
# 在项目根目录下执行 生成所需依赖包名、版本
pipreqs ./
# 安装所需依赖
pip install -r requirements.txt
PS D:\OtherProjects\action\practice-demo-python\src\python\xieyu>
PS D:\OtherProjects\action\practice-demo-python\src\python\xieyu> pipreqs --clean .\requirements.txt --encoding UTF-8 ./
INFO: Successfully cleaned up requirements in .\requirements.txt
PS D:\OtherProjects\action\practice-demo-python\src\python\xieyu> pipreqs --help
pipreqs - Generate pip requirements.txt file based on imports
Usage:
pipreqs [options] [<path>]
Arguments:
<path> The path to the directory containing the application
files for which a requirements file should be
generated (defaults to the current working
directory).
Options:
--use-local Use ONLY local package info instead of querying PyPI.
--pypi-server <url> Use custom PyPi server.
--proxy <url> Use Proxy, parameter will be passed to requests
library. You can also just set the environments
parameter in your terminal:
$ export HTTP_PROXY="http://10.10.1.10:3128"
$ export HTTPS_PROXY="https://10.10.1.10:1080"
--debug Print debug information
--ignore <dirs>... Ignore extra directories, each separated by a comma
--no-follow-links Do not follow symbolic links in the project
--encoding <charset> Use encoding parameter for file open
--savepath <file> Save the list of requirements in the given file
--print Output the list of requirements in the standard
output
--force Overwrite existing requirements.txt
--diff <file> Compare modules in requirements.txt to project
imports
--clean <file> Clean up requirements.txt by removing modules
that are not imported in project
--mode <scheme> Enables dynamic versioning with <compat>,
<gt> or <non-pin> schemes.
<compat> | e.g. Flask~=1.1.2
<gt> | e.g. Flask>=1.1.2
<no-pin> | e.g. Flask
PS D:\OtherProjects\action\practice-demo-python\src\python\xieyu>
PS D:\OtherProjects\action\practice-demo-python\src\python\xieyu> pip list
Package Version
------------------ ---------
asgiref 3.5.0
backports.zoneinfo 0.2.1
certifi 2021.10.8
charset-normalizer 2.0.11
Django 4.0.2
docopt 0.6.2
idna 3.3
pip 21.1.1
pipreqs 0.4.11
pycparser 2.21
pythonnet 2.5.2
requests 2.27.1
setuptools 56.0.0
sqlparse 0.4.2
tzdata 2021.5
urllib3 1.26.8
yarg 0.1.9
WARNING: You are using pip version 21.1.1; however, version 21.3.1 is available.
You should consider upgrading via the 'd:\devtools\python\python38-32\python.exe -m pip install --upgrade pip' command.
PS D:\OtherProjects\action\practice-demo-python\src\python\xieyu>
pipreps 命令只能根据 python 项目已安装的依赖分析出需要的包。也就是说,新git clone 下来的项目,如果本地没有项目所依赖的包,pipreqs 就无法分析出依赖的包。同时,如果本地的包与项目依赖的包版本不一致的话,分析出来的 requirements.txt 中为当前本地的版本。
所以,在项目中,需要建好 requirements.txt ,罗列好需要的依赖。git clone 后,根据 requirements.txt 安装 pip install -r requirements.txt。
python 环境设置
对于有多个 python 环境,本地该使用哪个呢,同时要避免包污染(下载了其它项目依赖的同名不同版本的包,原始的项目无法运行)。个人也很奇怪,pip 安装为什么指定了版本,也会把其它版本uninstall?下面是我安装 django==3.2.4,原来存在 4.0.2,结果先是卸载,再是安装。
PS D:\OtherProjects\action\practice-demo-python\src\python\day01\django> pip list
------------------ ---------
asgiref 3.5.0
backports.zoneinfo 0.2.1
certifi 2021.10.8
charset-normalizer 2.0.11
Django 4.0.2
docopt 0.6.2
idna 3.3
pip 21.1.1
pipreqs 0.4.11
pycparser 2.21
pythonnet 2.5.2
requests 2.27.1
setuptools 56.0.0
sqlparse 0.4.2
tzdata 2021.5
urllib3 1.26.8
yarg 0.1.9
WARNING: You are using pip version 21.1.1; however, version 21.3.1 is available.
You should consider upgrading via the 'd:\devtools\python\python38-32\python.exe -m pip install --upgrade pip' command.
PS D:\OtherProjects\action\practice-demo-python\src\python\day01\django> pip install Django==3.2.4
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting Django==3.2.4
Downloading https://mirrors.aliyun.com/pypi/packages/70/22/ed1943c0ef2be99ade872f49a20aa4cfc70eb4ffc866fc61b128211f3e5d/Django-3.2.4-py3-none-any.whl (7.9 MB)
|████████████████████████████████| 7.9 MB 3.2 MB/s
Requirement already satisfied: asgiref<4,>=3.3.2 in d:\devtools\python\python38-32\lib\site-packages (from Django==3.2.4) (3.5.0)
Collecting pytz
Downloading https://mirrors.aliyun.com/pypi/packages/d3/e3/d9f046b5d1c94a3aeab15f1f867aa414f8ee9d196fae6865f1d6a0ee1a0b/pytz-2021.3-py2.py3-none-any.whl (503 kB)
|████████████████████████████████| 503 kB ...
Requirement already satisfied: sqlparse>=0.2.2 in d:\devtools\python\python38-32\lib\site-packages (from Django==3.2.4) (0.4.2)
Installing collected packages: pytz, Django
Attempting uninstall: Django
Found existing installation: Django 4.0.2
Uninstalling Django-4.0.2:
Successfully uninstalled Django-4.0.2
Successfully installed Django-3.2.4 pytz-2021.3
WARNING: You are using pip version 21.1.1; however, version 21.3.1 is available.
You should consider upgrading via the 'd:\devtools\python\python38-32\python.exe -m pip install --upgrade pip' command.
PS D:\OtherProjects\action\practice-demo-python\src\python\day01\django>
不知道是不是由于这个原因,项目一般需要建立自己的venv,来管理自己需要的包,环境等,避免全局安装。<br />venv 模块在 python 较新的版本中已包含(不知道从那个开始的),我的如下: python27 的没有
PS D:\devTools\Python>
PS D:\devTools\Python> .\Python27\python.exe -m venv --help
D:\devTools\Python\Python27\python.exe: No module named venv
PS D:\devTools\Python>
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip] [--prompt PROMPT] ENV_DIR [ENV_DIR ...]
Creates virtual Python environments in one or more target directories.
positional arguments:
ENV_DIR A directory to create the environment in.
optional arguments:
-h, --help show this help message and exit
--system-site-packages
Give the virtual environment access to the system site-packages dir.
--symlinks Try to use symlinks rather than copies, when symlinks are not the default for the platform.
--copies Try to use copies rather than symlinks, even when symlinks are the default for the platform.
--clear Delete the contents of the environment directory if it already exists, before environment creation.
--upgrade Upgrade the environment directory to use this version of Python, assuming Python has been upgraded in-place.
--without-pip Skips installing or upgrading pip in the virtual environment (pip is bootstrapped by default)
--prompt PROMPT Provides an alternative prompt prefix for this environment.
Once an environment has been created, you may wish to activate it, e.g. by sourcing an activate script in its bin directory.
PS D:\devTools\Python>
PS D:\devTools\Python> .\Python310\python.exe -m venv --help
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps] ENV_DIR [ENV_DIR ...]
Creates virtual Python environments in one or more target directories.
positional arguments:
ENV_DIR A directory to create the environment in.
options:
-h, --help show this help message and exit
--system-site-packages
Give the virtual environment access to the system site-packages dir.
--symlinks Try to use symlinks rather than copies, when symlinks are not the default for the platform.
--copies Try to use copies rather than symlinks, even when symlinks are the default for the platform.
--clear Delete the contents of the environment directory if it already exists, before environment creation.
--upgrade Upgrade the environment directory to use this version of Python, assuming Python has been upgraded in-place.
--without-pip Skips installing or upgrading pip in the virtual environment (pip is bootstrapped by default)
--prompt PROMPT Provides an alternative prompt prefix for this environment.
--upgrade-deps Upgrade core dependencies: pip setuptools to the latest version in PyPI
Once an environment has been created, you may wish to activate it, e.g. by sourcing an activate script in its bin directory.
PS D:\devTools\Python>
先拿 python2.7.18 来说
当前没有 venv
PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python27\python.exe -m venv --help
D:\devTools\Python\Python27\python.exe: No module named venv
使用 virtualenv
参考: https://virtualenv-chinese-docs.readthedocs.io/en/latest/#id29
那就安装吧: pip install virtualenv
PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python27\Scripts\pip.exe install virtualenv
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting virtualenv
Downloading https://mirrors.aliyun.com/pypi/packages/ef/a1/4e1700f25211b3851e6be6675061e0c8eae7585d80177a40e9b02d1105d8/virtualenv-20.13.0-py2.py3-none-any.whl (6.5MB)
|████████████████████████████████| 6.6MB 3.2MB/s
Collecting importlib-metadata>=0.12; python_version < "3.8" (from virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/cf/b4/877779cd7b5a15536ecbe0655cfb35a0de0ede6d888151fd7356d278c47d/importlib_metadata-2.1.3-py2.py3-none-any.whl
Collecting distlib<1,>=0.3.1 (from virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/ac/a3/8ee4f54d5f12e16eeeda6b7df3dfdbda24e6cc572c86ff959a4ce110391b/distlib-0.3.4-py2.py3-none-any.whl (461kB)
|████████████████████████████████| 471kB 5.7MB/s
Collecting filelock<4,>=3.2 (from virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/f1/12/585c4d8bef61cd7f9497a021d935ba9fb3127f5e45593c2fcc313897f582/filelock-3.2.1-py2.py3-none-any.whl
Collecting platformdirs<3,>=2 (from virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/12/57/f4e6d433fba8bde239baa65f626a31fc6d0556a2065fcc81aaa0f4f1507b/platformdirs-2.0.2-py2.py3-none-any.whl
Collecting importlib-resources>=1.0; python_version < "3.7" (from virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/8d/94/2f6ceee0c4e63bff0177c07e68d27c937a19f6bc77c4739755b49f5adb04/importlib_resources-3.3.1-py2.py3-none-any.whl
Collecting six<2,>=1.9.0 (from virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl
Collecting configparser>=3.5; python_version < "3" (from importlib-metadata>=0.12; python_version < "3.8"->virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/7a/2a/95ed0501cf5d8709490b1d3a3f9b5cf340da6c433f896bbe9ce08dbe678Collecting contextlib2; python_version < "3" (from importlib-metadata>=0.12; python_version < "3.8"->virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/85/60/370352f7ef6aa96c52fb001831622f50f923c1d575427d021b8ab3311236/contextlib2-0.6.0.post1-py2.py3-none-any.whl
Collecting pathlib2; python_version < "3" (from importlib-metadata>=0.12; python_version < "3.8"->virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/76/67/dc02c72177ec79f0176e5bf9921e9c1745a381ed556afb3b3ecc2bb8ba2e/pathlib2-2.3.6-py2.py3-none-any.whl
Collecting zipp>=0.5 (from importlib-metadata>=0.12; python_version < "3.8"->virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/96/0a/67556e9b7782df7118c1f49bdc494da5e5e429c93aa77965f33e81287c8c/zipp-1.2.0-py2.py3-none-any.whl
Collecting typing; python_version < "3.5" (from importlib-resources>=1.0; python_version < "3.7"->virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/0b/cb/da856e81731833b94da70a08712f658416266a5fb2a9d9e426c8061becef/typing-3.10.0.0-py2-none-any.whl
Collecting singledispatch; python_version < "3.4" (from importlib-resources>=1.0; python_version < "3.7"->virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/3f/09/2a17c6505a8373229cb3de6161e3af74ff90afcf4516719aa6cf32fad151/singledispatch-3.7.0-py2.py3-none-any.whl
Collecting scandir; python_version < "3.5" (from pathlib2; python_version < "3"->importlib-metadata>=0.12; python_version < "3.8"->virtualenv)
Downloading https://mirrors.aliyun.com/pypi/packages/f9/d0/6b7b38eaf9964510f5c32aa5aaf9f419864d2e0ebe34274e6cba5689a0c5/scandir-1.10.0-cp27-cp27m-win_amd64.whl
Installing collected packages: configparser, contextlib2, scandir, six, pathlib2, zipp, importlib-metadata, distlib, filelock, platformdirs, typing, singledispatch, importlib-resources, virtualenv
WARNING: The script virtualenv.exe is installed in 'd:\devtools\python\python27\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed configparser-4.0.2 contextlib2-0.6.0.post1 distlib-0.3.4 filelock-3.2.1 importlib-metadata-2.1.3 importlib-resources-3.3.1 pathlib2-2.3.6 platformdirs-2.0.2 scandir-1.10.0 singledispatch-3.7.0 six-1.16.0 typing-3.10.0.0 virtualenv-20.13.0 zipp-1.2.0
WARNING: You are using pip version 19.2.3, however version 20.3.4 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
PS D:\OtherProjects\other\python\python_env27>
安装完后后,对应的 python_home\scripts 下回出现 virtualenv.exe,就使用该命令来创建 python venv 环境。
PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python27\Scripts\virtualenv.exe --python python2.5
RuntimeError: failed to find interpreter for Builtin discover of python_spec='python2.5'
# 指定的 python 要存在,不能随便整
PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python27\Scripts\virtualenv.exe --python D:\devTools\Python\Python27\python.exe python27_env
created virtual environment CPython2.7.18.final.0-64 in 1033ms
creator CPython2Windows(dest=D:\OtherProjects\other\python\python_env27\python27_env, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, wheel=bundle, setuptools=bundle, via=copy, app_data_dir=C:\Users\DELL\AppData\Local\pypa\virtualenv)
added seed packages: pip==20.3.4, setuptools==44.1.1, wheel==0.37.1
activators NushellActivator,PythonActivator,FishActivator,BatchActivator,PowerShellActivator,BashActivator
PS D:\OtherProjects\other\python\python_env27>
进入对应的虚拟环境
在 script 存在相应的脚本
PS D:\OtherProjects\other\python\python_env27\python27_env> cd .\Scripts\
PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts> .\activate
(python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts> python -V
Python 2.7.18
(python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts>
(python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts>
(python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts>
(python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts> python -m pip -V
(python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts>
(python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts> pip install minio
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting minio
Downloading https://mirrors.aliyun.com/pypi/packages/d2/fb/2a1e6207b56b9e1bed0589b8f7396eb77291d6e898b681ae0caba2b8ecec/minio-7.1.3.tar.gz (114 kB)
|████████████████████████████████| 114 kB 1.3 MB/s
Collecting certifi
5/certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
|████████████████████████████████| 149 kB 4.7 MB/s
Collecting urllib3
Downloading https://mirrors.aliyun.com/pypi/packages/4e/b8/f5a25b22e803f0578e668daa33ba3701bb37858ec80e08a150bd7d2cf1b1/urllib3-1.26.8-py2.py3-none-any.whl (138 kB)
|████████████████████████████████| 138 kB 2.8 MB/s
Building wheels for collected packages: minio
Building wheel for minio (setup.py) ... done
Created wheel for minio: filename=minio-7.1.3-py2-none-any.whl size=75600 sha256=1141aa1228fa4c9ddbf54731a975e83d2ace87157526b4bbe8241b0465d318fc
Stored in directory: c:\users\dell\appdata\local\pip\cache\wheels\f6\93\c8\6db5125483b68dc446ad5fc133ecb7c389f1f9d2d7b36edd44
Successfully built minio
Installing collected packages: certifi, urllib3, minio
Successfully installed certifi-2021.10.8 minio-7.1.3 urllib3-1.26.8
(python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts> pip list
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Package Version
---------- ---------
certifi 2021.10.8
minio 7.1.3
pip 20.3.4
setuptools 44.1.1
urllib3 1.26.8
wheel 0.37.1
(python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts> dir
目录: D:\OtherProjects\other\python\python_env27\python27_env\Scripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2022/2/12 15:16 2178 activate
-a---- 2022/2/12 15:16 1018 activate.bat
-a---- 2022/2/12 15:16 3055 activate.fish
-a---- 2022/2/12 15:16 1355 activate.nu
-a---- 2022/2/12 15:16 1758 activate.ps1
-a---- 2022/2/12 15:16 1198 activate_this.py
-a---- 2022/2/12 15:16 510 deactivate.bat
-a---- 2022/2/12 15:16 333 deactivate.nu
-a---- 2022/2/12 15:16 106906 easy_install-2.7.exe
-a---- 2022/2/12 15:16 106906 easy_install.exe
-a---- 2022/2/12 15:16 106906 easy_install2.7.exe
-a---- 2022/2/12 15:16 106906 easy_install2.exe
-a---- 2022/2/12 15:16 106897 pip-2.7.exe
-a---- 2022/2/12 15:16 106897 pip.exe
-a---- 2022/2/12 15:16 106897 pip2.7.exe
-a---- 2022/2/12 15:16 106897 pip2.exe
-a---- 2022/2/12 15:16 24 pydoc.bat
-a---- 2022/2/12 15:16 28160 python.exe
-a---- 2022/2/12 15:16 28160 pythonw.exe
-a---- 2022/2/12 15:16 106884 wheel-2.7.exe
-a---- 2022/2/12 15:16 106884 wheel.exe
-a---- 2022/2/12 15:16 106884 wheel2.7.exe
-a---- 2022/2/12 15:16 106884 wheel2.exe
(python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts>
(python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts> deactivate
PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts>
activate 激活虚拟环境,deactivate 退出虚拟环境
python38
使用 python -m venv dir_virtualenv
# 建立文件夹,用来表示一下而已
PS D:\OtherProjects\other\python> mkdir python_env38
目录: D:\OtherProjects\other\python
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2022/2/12 15:44 python_env38
PS D:\OtherProjects\other\python>
PS D:\OtherProjects\other\python>
PS D:\OtherProjects\other\python> cd .\python_env38\
PS D:\OtherProjects\other\python\python_env38>
PS D:\OtherProjects\other\python\python_env38>
# 查看帮助
PS D:\OtherProjects\other\python\python_env38> D:\devTools\Python\Python38\python.exe -m venv --help
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip]
[--prompt PROMPT]
ENV_DIR [ENV_DIR ...]
Creates virtual Python environments in one or more target directories.
positional arguments:
ENV_DIR A directory to create the environment in.
optional arguments:
-h, --help show this help message and exit
--system-site-packages
Give the virtual environment access to the system site-packages dir.
--symlinks Try to use symlinks rather than copies, when symlinks are not the default for the platform.
--copies Try to use copies rather than symlinks, even when symlinks are the default for the platform.
--clear Delete the contents of the environment directory if it already exists, before environment
creation.
--upgrade Upgrade the environment directory to use this version of Python, assuming Python has been
upgraded in-place.
--without-pip Skips installing or upgrading pip in the virtual environment (pip is bootstrapped by default)
--prompt PROMPT Provides an alternative prompt prefix for this environment.
Once an environment has been created, you may wish to activate it, e.g. by sourcing an activate script in its bin
directory.
# 创建虚拟环境
PS D:\OtherProjects\other\python\python_env38> D:\devTools\Python\Python38\python.exe -m venv .\python38_venv
PS D:\OtherProjects\other\python\python_env38>
PS D:\OtherProjects\other\python\python_env38>
# 进入虚拟环境目录
PS D:\OtherProjects\other\python\python_env38> cd .\python38_venv\
PS D:\OtherProjects\other\python\python_env38\python38_venv>
PS D:\OtherProjects\other\python\python_env38\python38_venv> dir
目录: D:\OtherProjects\other\python\python_env38\python38_venv
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2022/2/12 15:47 Include
d----- 2022/2/12 15:47 Lib
d----- 2022/2/12 15:47 Scripts
-a---- 2022/2/12 15:47 91 pyvenv.cfg
PS D:\OtherProjects\other\python\python_env38\python38_venv>
PS D:\OtherProjects\other\python\python_env38\python38_venv> cd .\Scripts\
PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts>
PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts> dir
目录: D:\OtherProjects\other\python\python_env38\python38_venv\Scripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2022/2/12 15:47 2334 activate
-a---- 2022/2/12 15:47 1002 activate.bat
-a---- 2022/2/12 15:47 18456 Activate.ps1
-a---- 2022/2/12 15:47 368 deactivate.bat
-a---- 2022/2/12 15:47 106395 easy_install-3.8.exe
-a---- 2022/2/12 15:47 106395 easy_install.exe
-a---- 2022/2/12 15:47 106386 pip.exe
-a---- 2022/2/12 15:47 106386 pip3.8.exe
-a---- 2022/2/12 15:47 106386 pip3.exe
-a---- 2022/2/12 15:47 532040 python.exe
-a---- 2022/2/12 15:47 531016 pythonw.exe
PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts>
# 激活环境
PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts> .\activate
(python38_venv) PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts>
(python38_venv) PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts> python -m pip list
Package Version
---------- -------
pip 20.1.1
setuptools 47.1.0
WARNING: You are using pip version 20.1.1; however, version 22.0.3 is available.
You should consider upgrading via the 'D:\OtherProjects\other\python\python_env38\python38_venv\Scripts\python.exe -m pip install --upgrade pip' command.
(python38_venv) PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts>
# 退出环境
(python38_venv) PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts> deactivate
PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts>
PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts>
疑惑:本机python38环境,如何建立python36环境或者python39环境
电脑上没有安装 python 环境,或者本机上安装的 python 环境与待运行的环境不一致。如何使用 venv 来实现项目开发运行?
方式一:项目全部上传,包括venv,对方应该就有了(没有试过,仅仅推测)
貌似没有办法,只有安装对应的环境 python。
就像java 一样,依赖 jdk ,就必须安装