本文所有的讨论都是为Django服务

python

1.查看所需安装版本

打开后台根目录下Pipfile文件
image.pngimage.png
如上,该项目序号的python版本为3.7。

2.安装

安装过程自行百度即可。
特殊情况下的安装(如电脑注册列表中存在以前安装的垃圾等导致安装不成功。)如下
image.png
正常情况下可以清除注册列表卸载重装等。如果不成功则一下操作以供参考。
1.复制同事的python,到你的安装目录下
2.添加python,python/scripts 到系统环境变量中
image.png
至此应该可以再cmd中访问到python
image.png

3.其他工作

1.pip安装

如果能访问python但是不能访问pip则需要额外对pip进行安装
image.png
访问Pip官网下载zip或whl 文件(如下)
image.png
解压至任意目录,进入该目录运行 python setup.py install
python将把pip安装至python目录中的scripts文件夹中
image.pngimage.png

2.移除冗余的包(保险起见对python目录下的scripts文件夹进行清扫,防止某些包不能正常使用)

使用 pip list 查看现存的包。除wheel setuptools 与刚重新安装的pip 之外全部使用pip uninstall卸载(或重新安装)
image.png

pipenv

1.简介

pipenv结合了 Pipfile,pip,和virtualenv,能够有效管理Python多个环境,各种包。
过去我们一般用virtualenv搭建虚拟环境,管理python版本,但是跨平台的使用不太一致,且有时候处理包之间的依赖总存在问题;过去也常常用 pip进行包的管理,pip已经足够好,但是仍然推荐pipenv,相当于virtualenv和pip的合体,且更加强大。

2.Pipfile

Pipfile是社区拟定的依赖管理文件,用于替代过于简陋的 requirements.txt 文件。Pipfile 文件是 TOML 格式而不是 requirements.txt 这样的纯文本。
image.png
简单来说Pipfile就是记录了该项目的各种依赖。
image.png

3.安装

  1. pip install pipenv

4.常用操作

1.初始化项目环境 pipenv install —dev

  1. Install all dependencies for a project (including dev):
  2. pipenv install --dev

使用pipenv install —dev 后会(默认)在系统用户下的.virtualenvs文件夹内安装生成该项目的专属环境。
image.png
2.进入编辑环境

  1. Spawns a shell within the virtualenv
  2. pipenv shell

3.删除虚拟环境

  1. Remove project virtualenv (inferred from current directory):
  2. pipenv --rm

(题外话)可也进入系统用户下的.virtualenvs目录删除对应的虚拟环境。

5.常见其他操作

1.pipenv命令与使用方法

  1. Usage: pipenv [OPTIONS] COMMAND [ARGS]...
  2. Options:
  3. --where Output project home information.
  4. --venv Output virtualenv information.
  5. --py Output Python interpreter information.
  6. --envs Output Environment Variable options.
  7. --rm Remove the virtualenv.
  8. --bare Minimal output.
  9. --man Display manpage.
  10. --support Output diagnostic information for use in
  11. GitHub issues.
  12. --site-packages / --no-site-packages
  13. Enable site-packages for the virtualenv.
  14. [env var: PIPENV_SITE_PACKAGES]
  15. --python TEXT Specify which version of Python virtualenv
  16. should use.
  17. --three Use Python 3 when creating virtualenv.
  18. --clear Clears caches (pipenv, pip). [env var:
  19. PIPENV_CLEAR]
  20. -q, --quiet Quiet mode.
  21. -v, --verbose Verbose mode.
  22. --pypi-mirror TEXT Specify a PyPI mirror.
  23. --version Show the version and exit.
  24. -h, --help Show this message and exit.

2.命令解释

  1. Commands:
  2. check Checks for PyUp Safety security vulnerabilities and against
  3. PEP 508 markers provided in Pipfile.
  4. clean Uninstalls all packages not specified in Pipfile.lock.
  5. graph Displays currently-installed dependency graph information.
  6. install Installs provided packages and adds them to Pipfile, or (if no
  7. packages are given), installs all packages from Pipfile.
  8. lock Generates Pipfile.lock.
  9. open View a given module in your editor.
  10. requirements Generate a requirements.txt from Pipfile.lock.
  11. run Spawns a command installed into the virtualenv.
  12. scripts Lists scripts in current environment config.
  13. shell Spawns a shell within the virtualenv.
  14. sync Installs all packages specified in Pipfile.lock.
  15. uninstall Uninstalls a provided package and removes it from Pipfile.
  16. update Runs lock, then sync.
  17. verify Verify the hash in Pipfile.lock is up-to-date.

3.使用demo

  1. Usage Examples:
  2. Create a new project using Python 3.7, specifically:
  3. $ pipenv --python 3.7
  4. Remove project virtualenv (inferred from current directory):
  5. $ pipenv --rm
  6. Install all dependencies for a project (including dev):
  7. $ pipenv install --dev
  8. Create a lockfile containing pre-releases:
  9. $ pipenv lock --pre
  10. Show a graph of your installed dependencies:
  11. $ pipenv graph
  12. Check your installed dependencies for security vulnerabilities:
  13. $ pipenv check
  14. Install a local setup.py into your virtual environment/Pipfile:
  15. $ pipenv install -e .
  16. Use a lower-level pip command:
  17. $ pipenv run pip freeze

6.完整的日常使用demo

Django项目

  1. pipenv install —dev 安装依赖
  2. pipenv shell 进入虚拟环境
  3. python manage.py runserver [port] [ip:port] 运行Django服务

image.png