下载 python 安装包

地址:https://www.python.org/downloads 选择需要的 python 安装包

  1. PS D:\downloads> dir
  2. 目录: D:\downloads
  3. Mode LastWriteTime Length Name
  4. ---- ------------- ------ ----
  5. -a---- 2021/11/29 9:10 20598784 python-2.7.18.amd64.msi
  6. -a---- 2022/2/12 11:32 19632128 python-2.7.18.msi
  7. -a---- 2021/11/29 9:09 28315928 python-3.10.0-amd64.exe
  8. -a---- 2022/2/7 14:19 27204536 python-3.8.10.exe
  9. -a---- 2022/1/23 8:59 27866224 python-3.8.4-amd64.exe
  10. -a---- 2022/1/21 18:34 1914683 pythonnet-2.5.2.tar.gz
  11. PS D:\downloads>

安装下载的包

注意,开发中常常需要各个版本的 python 安装包,所以建议设置一下安装路径,不需要将 python 加入到环境变量中去(需要的话,可以添加;当然也可以手动添加 %python_home%,以及 %python_home%/Scripts 到 path 中去)。

  1. PS D:\downloads> cd ..\devTools\Python\
  2. PS D:\devTools\Python>
  3. PS D:\devTools\Python> dir
  4. 目录: D:\devTools\Python
  5. Mode LastWriteTime Length Name
  6. ---- ------------- ------ ----
  7. d----- 2022/2/12 11:35 Python27
  8. d----- 2022/2/12 11:36 Python27-32
  9. d----- 2022/2/12 11:41 Python310
  10. d----- 2022/1/23 9:03 Python38
  11. d----- 2022/2/7 14:21 Python38-32
  12. PS D:\devTools\Python>

配置pip

  1. 1. c盘用户下建立 pip 目录
  2. 2. 进入 pip 目录,创建文件 pip.ini
  3. 3. 编辑 pip.ini,内容如下:
  4. [global]
  5. index-url = https://mirrors.aliyun.com/pypi/simple/
  6. [install]
  7. trusted-host=mirrors.aliyun.com

查看 pip 配置

  1. PS D:\OtherProjects\action\practice-demo-python> pip config list
  2. global.index-url='https://mirrors.aliyun.com/pypi/simple/'
  3. install.trusted-host='mirrors.aliyun.com'
  4. PS D:\OtherProjects\action\practice-demo-python>

pip list 查看本地所有安装的包

  1. PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python27\Scripts\pip.exe list
  2. 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
  3. Package Version
  4. ---------- -------
  5. pip 19.2.3
  6. setuptools 41.2.0
  7. WARNING: You are using pip version 19.2.3, however version 20.3.4 is available.
  8. You should consider upgrading via the 'python -m pip install --upgrade pip' command.
  9. PS D:\OtherProjects\other\python\python_env27>

pip freeze [> file.txt] 导出当前环境安装的所有包

注意:该命令是导出环境,不是项目依赖的包!

  1. PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python27\Scripts\pip.exe freeze
  2. 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
  3. # 新环境,还没得???加上 --all 就可以看到了
  4. PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python27\Scripts\pip.exe freeze --all
  5. 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
  6. pip==19.2.3
  7. setuptools==41.2.0
  8. PS D:\OtherProjects\other\python\python_env27>
  9. PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python38\Scripts\pip.exe freeze
  10. aliyun-python-sdk-alidns==2.6.29
  11. aliyun-python-sdk-core==2.13.35
  12. asgiref==3.3.4
  13. backports.zoneinfo==0.2.1
  14. cachetools==4.2.2
  15. certifi==2021.5.30
  16. cffi==1.15.0
  17. chardet==4.0.0
  18. coreapi==2.3.3
  19. coreschema==0.0.4
  20. cryptography==36.0.1
  21. Django==3.2.4
  22. djangorestframework==3.13.1
  23. drf-yasg==1.20.0
  24. fuzzywuzzy==0.18.0
  25. google-auth==1.31.0
  26. idna==2.10
  27. inflection==0.5.1
  28. itypes==1.2.0
  29. Jinja2==3.0.3
  30. jmespath==0.10.0
  31. kubernetes==18.20.0b1
  32. MarkupSafe==2.0.1
  33. minio==7.1.0
  34. mysql-connector==2.2.9
  35. oauthlib==3.1.1
  36. packaging==21.3
  37. pyasn1==0.4.8
  38. pyasn1-modules==0.2.8
  39. pycparser==2.21
  40. pyparsing==3.0.7
  41. python-dateutil==2.8.1
  42. pythonnet==2.5.2
  43. pytz==2021.1
  44. PyYAML==5.4.1
  45. requests==2.25.1
  46. requests-oauthlib==1.3.0
  47. rsa==4.7.2
  48. ruamel.yaml==0.17.20
  49. ruamel.yaml.clib==0.2.6
  50. six==1.16.0
  51. sqlparse==0.4.1
  52. typing-extensions==3.10.0.0
  53. tzdata==2021.5
  54. uritemplate==4.1.1
  55. urllib3==1.26.5
  56. websocket-client==1.1.0
  57. PS D:\OtherProjects\other\python\python_env27>

包管理 pipreqs

  1. # 安装pipreqs工具
  2. pip install pipreqs
  3. # 在项目根目录下执行 生成所需依赖包名、版本
  4. pipreqs ./
  5. # 安装所需依赖
  6. pip install -r requirements.txt
  1. PS D:\OtherProjects\action\practice-demo-python\src\python\xieyu>
  2. PS D:\OtherProjects\action\practice-demo-python\src\python\xieyu> pipreqs --clean .\requirements.txt --encoding UTF-8 ./
  3. INFO: Successfully cleaned up requirements in .\requirements.txt
  4. PS D:\OtherProjects\action\practice-demo-python\src\python\xieyu> pipreqs --help
  5. pipreqs - Generate pip requirements.txt file based on imports
  6. Usage:
  7. pipreqs [options] [<path>]
  8. Arguments:
  9. <path> The path to the directory containing the application
  10. files for which a requirements file should be
  11. generated (defaults to the current working
  12. directory).
  13. Options:
  14. --use-local Use ONLY local package info instead of querying PyPI.
  15. --pypi-server <url> Use custom PyPi server.
  16. --proxy <url> Use Proxy, parameter will be passed to requests
  17. library. You can also just set the environments
  18. parameter in your terminal:
  19. $ export HTTP_PROXY="http://10.10.1.10:3128"
  20. $ export HTTPS_PROXY="https://10.10.1.10:1080"
  21. --debug Print debug information
  22. --ignore <dirs>... Ignore extra directories, each separated by a comma
  23. --no-follow-links Do not follow symbolic links in the project
  24. --encoding <charset> Use encoding parameter for file open
  25. --savepath <file> Save the list of requirements in the given file
  26. --print Output the list of requirements in the standard
  27. output
  28. --force Overwrite existing requirements.txt
  29. --diff <file> Compare modules in requirements.txt to project
  30. imports
  31. --clean <file> Clean up requirements.txt by removing modules
  32. that are not imported in project
  33. --mode <scheme> Enables dynamic versioning with <compat>,
  34. <gt> or <non-pin> schemes.
  35. <compat> | e.g. Flask~=1.1.2
  36. <gt> | e.g. Flask>=1.1.2
  37. <no-pin> | e.g. Flask
  38. PS D:\OtherProjects\action\practice-demo-python\src\python\xieyu>
  39. PS D:\OtherProjects\action\practice-demo-python\src\python\xieyu> pip list
  40. Package Version
  41. ------------------ ---------
  42. asgiref 3.5.0
  43. backports.zoneinfo 0.2.1
  44. certifi 2021.10.8
  45. charset-normalizer 2.0.11
  46. Django 4.0.2
  47. docopt 0.6.2
  48. idna 3.3
  49. pip 21.1.1
  50. pipreqs 0.4.11
  51. pycparser 2.21
  52. pythonnet 2.5.2
  53. requests 2.27.1
  54. setuptools 56.0.0
  55. sqlparse 0.4.2
  56. tzdata 2021.5
  57. urllib3 1.26.8
  58. yarg 0.1.9
  59. WARNING: You are using pip version 21.1.1; however, version 21.3.1 is available.
  60. You should consider upgrading via the 'd:\devtools\python\python38-32\python.exe -m pip install --upgrade pip' command.
  61. 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,结果先是卸载,再是安装。

  1. PS D:\OtherProjects\action\practice-demo-python\src\python\day01\django> pip list
  2. ------------------ ---------
  3. asgiref 3.5.0
  4. backports.zoneinfo 0.2.1
  5. certifi 2021.10.8
  6. charset-normalizer 2.0.11
  7. Django 4.0.2
  8. docopt 0.6.2
  9. idna 3.3
  10. pip 21.1.1
  11. pipreqs 0.4.11
  12. pycparser 2.21
  13. pythonnet 2.5.2
  14. requests 2.27.1
  15. setuptools 56.0.0
  16. sqlparse 0.4.2
  17. tzdata 2021.5
  18. urllib3 1.26.8
  19. yarg 0.1.9
  20. WARNING: You are using pip version 21.1.1; however, version 21.3.1 is available.
  21. You should consider upgrading via the 'd:\devtools\python\python38-32\python.exe -m pip install --upgrade pip' command.
  22. PS D:\OtherProjects\action\practice-demo-python\src\python\day01\django> pip install Django==3.2.4
  23. Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
  24. Collecting Django==3.2.4
  25. Downloading https://mirrors.aliyun.com/pypi/packages/70/22/ed1943c0ef2be99ade872f49a20aa4cfc70eb4ffc866fc61b128211f3e5d/Django-3.2.4-py3-none-any.whl (7.9 MB)
  26. |████████████████████████████████| 7.9 MB 3.2 MB/s
  27. 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)
  28. Collecting pytz
  29. Downloading https://mirrors.aliyun.com/pypi/packages/d3/e3/d9f046b5d1c94a3aeab15f1f867aa414f8ee9d196fae6865f1d6a0ee1a0b/pytz-2021.3-py2.py3-none-any.whl (503 kB)
  30. |████████████████████████████████| 503 kB ...
  31. Requirement already satisfied: sqlparse>=0.2.2 in d:\devtools\python\python38-32\lib\site-packages (from Django==3.2.4) (0.4.2)
  32. Installing collected packages: pytz, Django
  33. Attempting uninstall: Django
  34. Found existing installation: Django 4.0.2
  35. Uninstalling Django-4.0.2:
  36. Successfully uninstalled Django-4.0.2
  37. Successfully installed Django-3.2.4 pytz-2021.3
  38. WARNING: You are using pip version 21.1.1; however, version 21.3.1 is available.
  39. You should consider upgrading via the 'd:\devtools\python\python38-32\python.exe -m pip install --upgrade pip' command.
  40. PS D:\OtherProjects\action\practice-demo-python\src\python\day01\django>
  1. 不知道是不是由于这个原因,项目一般需要建立自己的venv,来管理自己需要的包,环境等,避免全局安装。<br />venv 模块在 python 较新的版本中已包含(不知道从那个开始的),我的如下: python27 的没有
  1. PS D:\devTools\Python>
  2. PS D:\devTools\Python> .\Python27\python.exe -m venv --help
  3. D:\devTools\Python\Python27\python.exe: No module named venv
  4. PS D:\devTools\Python>
  5. usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip] [--prompt PROMPT] ENV_DIR [ENV_DIR ...]
  6. Creates virtual Python environments in one or more target directories.
  7. positional arguments:
  8. ENV_DIR A directory to create the environment in.
  9. optional arguments:
  10. -h, --help show this help message and exit
  11. --system-site-packages
  12. Give the virtual environment access to the system site-packages dir.
  13. --symlinks Try to use symlinks rather than copies, when symlinks are not the default for the platform.
  14. --copies Try to use copies rather than symlinks, even when symlinks are the default for the platform.
  15. --clear Delete the contents of the environment directory if it already exists, before environment creation.
  16. --upgrade Upgrade the environment directory to use this version of Python, assuming Python has been upgraded in-place.
  17. --without-pip Skips installing or upgrading pip in the virtual environment (pip is bootstrapped by default)
  18. --prompt PROMPT Provides an alternative prompt prefix for this environment.
  19. Once an environment has been created, you may wish to activate it, e.g. by sourcing an activate script in its bin directory.
  20. PS D:\devTools\Python>
  21. PS D:\devTools\Python> .\Python310\python.exe -m venv --help
  22. usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps] ENV_DIR [ENV_DIR ...]
  23. Creates virtual Python environments in one or more target directories.
  24. positional arguments:
  25. ENV_DIR A directory to create the environment in.
  26. options:
  27. -h, --help show this help message and exit
  28. --system-site-packages
  29. Give the virtual environment access to the system site-packages dir.
  30. --symlinks Try to use symlinks rather than copies, when symlinks are not the default for the platform.
  31. --copies Try to use copies rather than symlinks, even when symlinks are the default for the platform.
  32. --clear Delete the contents of the environment directory if it already exists, before environment creation.
  33. --upgrade Upgrade the environment directory to use this version of Python, assuming Python has been upgraded in-place.
  34. --without-pip Skips installing or upgrading pip in the virtual environment (pip is bootstrapped by default)
  35. --prompt PROMPT Provides an alternative prompt prefix for this environment.
  36. --upgrade-deps Upgrade core dependencies: pip setuptools to the latest version in PyPI
  37. Once an environment has been created, you may wish to activate it, e.g. by sourcing an activate script in its bin directory.
  38. PS D:\devTools\Python>

先拿 python2.7.18 来说

当前没有 venv

  1. PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python27\python.exe -m venv --help
  2. D:\devTools\Python\Python27\python.exe: No module named venv

使用 virtualenv

参考: https://virtualenv-chinese-docs.readthedocs.io/en/latest/#id29

那就安装吧: pip install virtualenv

  1. PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python27\Scripts\pip.exe install virtualenv
  2. 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
  3. Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
  4. Collecting virtualenv
  5. Downloading https://mirrors.aliyun.com/pypi/packages/ef/a1/4e1700f25211b3851e6be6675061e0c8eae7585d80177a40e9b02d1105d8/virtualenv-20.13.0-py2.py3-none-any.whl (6.5MB)
  6. |████████████████████████████████| 6.6MB 3.2MB/s
  7. Collecting importlib-metadata>=0.12; python_version < "3.8" (from virtualenv)
  8. Downloading https://mirrors.aliyun.com/pypi/packages/cf/b4/877779cd7b5a15536ecbe0655cfb35a0de0ede6d888151fd7356d278c47d/importlib_metadata-2.1.3-py2.py3-none-any.whl
  9. Collecting distlib<1,>=0.3.1 (from virtualenv)
  10. Downloading https://mirrors.aliyun.com/pypi/packages/ac/a3/8ee4f54d5f12e16eeeda6b7df3dfdbda24e6cc572c86ff959a4ce110391b/distlib-0.3.4-py2.py3-none-any.whl (461kB)
  11. |████████████████████████████████| 471kB 5.7MB/s
  12. Collecting filelock<4,>=3.2 (from virtualenv)
  13. Downloading https://mirrors.aliyun.com/pypi/packages/f1/12/585c4d8bef61cd7f9497a021d935ba9fb3127f5e45593c2fcc313897f582/filelock-3.2.1-py2.py3-none-any.whl
  14. Collecting platformdirs<3,>=2 (from virtualenv)
  15. Downloading https://mirrors.aliyun.com/pypi/packages/12/57/f4e6d433fba8bde239baa65f626a31fc6d0556a2065fcc81aaa0f4f1507b/platformdirs-2.0.2-py2.py3-none-any.whl
  16. Collecting importlib-resources>=1.0; python_version < "3.7" (from virtualenv)
  17. Downloading https://mirrors.aliyun.com/pypi/packages/8d/94/2f6ceee0c4e63bff0177c07e68d27c937a19f6bc77c4739755b49f5adb04/importlib_resources-3.3.1-py2.py3-none-any.whl
  18. Collecting six<2,>=1.9.0 (from virtualenv)
  19. Downloading https://mirrors.aliyun.com/pypi/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl
  20. Collecting configparser>=3.5; python_version < "3" (from importlib-metadata>=0.12; python_version < "3.8"->virtualenv)
  21. Downloading https://mirrors.aliyun.com/pypi/packages/7a/2a/95ed0501cf5d8709490b1d3a3f9b5cf340da6c433f896bbe9ce08dbe678Collecting contextlib2; python_version < "3" (from importlib-metadata>=0.12; python_version < "3.8"->virtualenv)
  22. Downloading https://mirrors.aliyun.com/pypi/packages/85/60/370352f7ef6aa96c52fb001831622f50f923c1d575427d021b8ab3311236/contextlib2-0.6.0.post1-py2.py3-none-any.whl
  23. Collecting pathlib2; python_version < "3" (from importlib-metadata>=0.12; python_version < "3.8"->virtualenv)
  24. Downloading https://mirrors.aliyun.com/pypi/packages/76/67/dc02c72177ec79f0176e5bf9921e9c1745a381ed556afb3b3ecc2bb8ba2e/pathlib2-2.3.6-py2.py3-none-any.whl
  25. Collecting zipp>=0.5 (from importlib-metadata>=0.12; python_version < "3.8"->virtualenv)
  26. Downloading https://mirrors.aliyun.com/pypi/packages/96/0a/67556e9b7782df7118c1f49bdc494da5e5e429c93aa77965f33e81287c8c/zipp-1.2.0-py2.py3-none-any.whl
  27. Collecting typing; python_version < "3.5" (from importlib-resources>=1.0; python_version < "3.7"->virtualenv)
  28. Downloading https://mirrors.aliyun.com/pypi/packages/0b/cb/da856e81731833b94da70a08712f658416266a5fb2a9d9e426c8061becef/typing-3.10.0.0-py2-none-any.whl
  29. Collecting singledispatch; python_version < "3.4" (from importlib-resources>=1.0; python_version < "3.7"->virtualenv)
  30. Downloading https://mirrors.aliyun.com/pypi/packages/3f/09/2a17c6505a8373229cb3de6161e3af74ff90afcf4516719aa6cf32fad151/singledispatch-3.7.0-py2.py3-none-any.whl
  31. Collecting scandir; python_version < "3.5" (from pathlib2; python_version < "3"->importlib-metadata>=0.12; python_version < "3.8"->virtualenv)
  32. Downloading https://mirrors.aliyun.com/pypi/packages/f9/d0/6b7b38eaf9964510f5c32aa5aaf9f419864d2e0ebe34274e6cba5689a0c5/scandir-1.10.0-cp27-cp27m-win_amd64.whl
  33. Installing collected packages: configparser, contextlib2, scandir, six, pathlib2, zipp, importlib-metadata, distlib, filelock, platformdirs, typing, singledispatch, importlib-resources, virtualenv
  34. WARNING: The script virtualenv.exe is installed in 'd:\devtools\python\python27\Scripts' which is not on PATH.
  35. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  36. 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
  37. WARNING: You are using pip version 19.2.3, however version 20.3.4 is available.
  38. You should consider upgrading via the 'python -m pip install --upgrade pip' command.
  39. PS D:\OtherProjects\other\python\python_env27>

安装完后后,对应的 python_home\scripts 下回出现 virtualenv.exe,就使用该命令来创建 python venv 环境。

  1. PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python27\Scripts\virtualenv.exe --python python2.5
  2. RuntimeError: failed to find interpreter for Builtin discover of python_spec='python2.5'
  3. # 指定的 python 要存在,不能随便整
  4. PS D:\OtherProjects\other\python\python_env27> D:\devTools\Python\Python27\Scripts\virtualenv.exe --python D:\devTools\Python\Python27\python.exe python27_env
  5. created virtual environment CPython2.7.18.final.0-64 in 1033ms
  6. creator CPython2Windows(dest=D:\OtherProjects\other\python\python_env27\python27_env, clear=False, no_vcs_ignore=False, global=False)
  7. seeder FromAppData(download=False, pip=bundle, wheel=bundle, setuptools=bundle, via=copy, app_data_dir=C:\Users\DELL\AppData\Local\pypa\virtualenv)
  8. added seed packages: pip==20.3.4, setuptools==44.1.1, wheel==0.37.1
  9. activators NushellActivator,PythonActivator,FishActivator,BatchActivator,PowerShellActivator,BashActivator
  10. PS D:\OtherProjects\other\python\python_env27>

进入对应的虚拟环境

在 script 存在相应的脚本

  1. PS D:\OtherProjects\other\python\python_env27\python27_env> cd .\Scripts\
  2. PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts> .\activate
  3. (python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts> python -V
  4. Python 2.7.18
  5. (python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts>
  6. (python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts>
  7. (python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts>
  8. (python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts> python -m pip -V
  9. (python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts>
  10. (python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts> pip install minio
  11. 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.
  12. Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
  13. Collecting minio
  14. Downloading https://mirrors.aliyun.com/pypi/packages/d2/fb/2a1e6207b56b9e1bed0589b8f7396eb77291d6e898b681ae0caba2b8ecec/minio-7.1.3.tar.gz (114 kB)
  15. |████████████████████████████████| 114 kB 1.3 MB/s
  16. Collecting certifi
  17. 5/certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
  18. |████████████████████████████████| 149 kB 4.7 MB/s
  19. Collecting urllib3
  20. Downloading https://mirrors.aliyun.com/pypi/packages/4e/b8/f5a25b22e803f0578e668daa33ba3701bb37858ec80e08a150bd7d2cf1b1/urllib3-1.26.8-py2.py3-none-any.whl (138 kB)
  21. |████████████████████████████████| 138 kB 2.8 MB/s
  22. Building wheels for collected packages: minio
  23. Building wheel for minio (setup.py) ... done
  24. Created wheel for minio: filename=minio-7.1.3-py2-none-any.whl size=75600 sha256=1141aa1228fa4c9ddbf54731a975e83d2ace87157526b4bbe8241b0465d318fc
  25. Stored in directory: c:\users\dell\appdata\local\pip\cache\wheels\f6\93\c8\6db5125483b68dc446ad5fc133ecb7c389f1f9d2d7b36edd44
  26. Successfully built minio
  27. Installing collected packages: certifi, urllib3, minio
  28. Successfully installed certifi-2021.10.8 minio-7.1.3 urllib3-1.26.8
  29. (python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts> pip list
  30. 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.
  31. Package Version
  32. ---------- ---------
  33. certifi 2021.10.8
  34. minio 7.1.3
  35. pip 20.3.4
  36. setuptools 44.1.1
  37. urllib3 1.26.8
  38. wheel 0.37.1
  39. (python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts> dir
  40. 目录: D:\OtherProjects\other\python\python_env27\python27_env\Scripts
  41. Mode LastWriteTime Length Name
  42. ---- ------------- ------ ----
  43. -a---- 2022/2/12 15:16 2178 activate
  44. -a---- 2022/2/12 15:16 1018 activate.bat
  45. -a---- 2022/2/12 15:16 3055 activate.fish
  46. -a---- 2022/2/12 15:16 1355 activate.nu
  47. -a---- 2022/2/12 15:16 1758 activate.ps1
  48. -a---- 2022/2/12 15:16 1198 activate_this.py
  49. -a---- 2022/2/12 15:16 510 deactivate.bat
  50. -a---- 2022/2/12 15:16 333 deactivate.nu
  51. -a---- 2022/2/12 15:16 106906 easy_install-2.7.exe
  52. -a---- 2022/2/12 15:16 106906 easy_install.exe
  53. -a---- 2022/2/12 15:16 106906 easy_install2.7.exe
  54. -a---- 2022/2/12 15:16 106906 easy_install2.exe
  55. -a---- 2022/2/12 15:16 106897 pip-2.7.exe
  56. -a---- 2022/2/12 15:16 106897 pip.exe
  57. -a---- 2022/2/12 15:16 106897 pip2.7.exe
  58. -a---- 2022/2/12 15:16 106897 pip2.exe
  59. -a---- 2022/2/12 15:16 24 pydoc.bat
  60. -a---- 2022/2/12 15:16 28160 python.exe
  61. -a---- 2022/2/12 15:16 28160 pythonw.exe
  62. -a---- 2022/2/12 15:16 106884 wheel-2.7.exe
  63. -a---- 2022/2/12 15:16 106884 wheel.exe
  64. -a---- 2022/2/12 15:16 106884 wheel2.7.exe
  65. -a---- 2022/2/12 15:16 106884 wheel2.exe
  66. (python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts>
  67. (python27_env) PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts> deactivate
  68. PS D:\OtherProjects\other\python\python_env27\python27_env\Scripts>
  1. activate 激活虚拟环境,deactivate 退出虚拟环境

python38

使用 python -m venv dir_virtualenv

  1. # 建立文件夹,用来表示一下而已
  2. PS D:\OtherProjects\other\python> mkdir python_env38
  3. 目录: D:\OtherProjects\other\python
  4. Mode LastWriteTime Length Name
  5. ---- ------------- ------ ----
  6. d----- 2022/2/12 15:44 python_env38
  7. PS D:\OtherProjects\other\python>
  8. PS D:\OtherProjects\other\python>
  9. PS D:\OtherProjects\other\python> cd .\python_env38\
  10. PS D:\OtherProjects\other\python\python_env38>
  11. PS D:\OtherProjects\other\python\python_env38>
  12. # 查看帮助
  13. PS D:\OtherProjects\other\python\python_env38> D:\devTools\Python\Python38\python.exe -m venv --help
  14. usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip]
  15. [--prompt PROMPT]
  16. ENV_DIR [ENV_DIR ...]
  17. Creates virtual Python environments in one or more target directories.
  18. positional arguments:
  19. ENV_DIR A directory to create the environment in.
  20. optional arguments:
  21. -h, --help show this help message and exit
  22. --system-site-packages
  23. Give the virtual environment access to the system site-packages dir.
  24. --symlinks Try to use symlinks rather than copies, when symlinks are not the default for the platform.
  25. --copies Try to use copies rather than symlinks, even when symlinks are the default for the platform.
  26. --clear Delete the contents of the environment directory if it already exists, before environment
  27. creation.
  28. --upgrade Upgrade the environment directory to use this version of Python, assuming Python has been
  29. upgraded in-place.
  30. --without-pip Skips installing or upgrading pip in the virtual environment (pip is bootstrapped by default)
  31. --prompt PROMPT Provides an alternative prompt prefix for this environment.
  32. Once an environment has been created, you may wish to activate it, e.g. by sourcing an activate script in its bin
  33. directory.
  34. # 创建虚拟环境
  35. PS D:\OtherProjects\other\python\python_env38> D:\devTools\Python\Python38\python.exe -m venv .\python38_venv
  36. PS D:\OtherProjects\other\python\python_env38>
  37. PS D:\OtherProjects\other\python\python_env38>
  38. # 进入虚拟环境目录
  39. PS D:\OtherProjects\other\python\python_env38> cd .\python38_venv\
  40. PS D:\OtherProjects\other\python\python_env38\python38_venv>
  41. PS D:\OtherProjects\other\python\python_env38\python38_venv> dir
  42. 目录: D:\OtherProjects\other\python\python_env38\python38_venv
  43. Mode LastWriteTime Length Name
  44. ---- ------------- ------ ----
  45. d----- 2022/2/12 15:47 Include
  46. d----- 2022/2/12 15:47 Lib
  47. d----- 2022/2/12 15:47 Scripts
  48. -a---- 2022/2/12 15:47 91 pyvenv.cfg
  49. PS D:\OtherProjects\other\python\python_env38\python38_venv>
  50. PS D:\OtherProjects\other\python\python_env38\python38_venv> cd .\Scripts\
  51. PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts>
  52. PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts> dir
  53. 目录: D:\OtherProjects\other\python\python_env38\python38_venv\Scripts
  54. Mode LastWriteTime Length Name
  55. ---- ------------- ------ ----
  56. -a---- 2022/2/12 15:47 2334 activate
  57. -a---- 2022/2/12 15:47 1002 activate.bat
  58. -a---- 2022/2/12 15:47 18456 Activate.ps1
  59. -a---- 2022/2/12 15:47 368 deactivate.bat
  60. -a---- 2022/2/12 15:47 106395 easy_install-3.8.exe
  61. -a---- 2022/2/12 15:47 106395 easy_install.exe
  62. -a---- 2022/2/12 15:47 106386 pip.exe
  63. -a---- 2022/2/12 15:47 106386 pip3.8.exe
  64. -a---- 2022/2/12 15:47 106386 pip3.exe
  65. -a---- 2022/2/12 15:47 532040 python.exe
  66. -a---- 2022/2/12 15:47 531016 pythonw.exe
  67. PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts>
  68. # 激活环境
  69. PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts> .\activate
  70. (python38_venv) PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts>
  71. (python38_venv) PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts> python -m pip list
  72. Package Version
  73. ---------- -------
  74. pip 20.1.1
  75. setuptools 47.1.0
  76. WARNING: You are using pip version 20.1.1; however, version 22.0.3 is available.
  77. You should consider upgrading via the 'D:\OtherProjects\other\python\python_env38\python38_venv\Scripts\python.exe -m pip install --upgrade pip' command.
  78. (python38_venv) PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts>
  79. # 退出环境
  80. (python38_venv) PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts> deactivate
  81. PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts>
  82. PS D:\OtherProjects\other\python\python_env38\python38_venv\Scripts>

疑惑:本机python38环境,如何建立python36环境或者python39环境

电脑上没有安装 python 环境,或者本机上安装的 python 环境与待运行的环境不一致。如何使用 venv 来实现项目开发运行?

方式一:项目全部上传,包括venv,对方应该就有了(没有试过,仅仅推测)

貌似没有办法,只有安装对应的环境 python。

就像java 一样,依赖 jdk ,就必须安装