• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
孙龙 程序员
少时总觉为人易,华年方知立业难
博客园    首页    新随笔    联系   管理    订阅  订阅
CentOS 7.4 安装python3及虚拟环境 pipenv

前言

安装python3.6.4

https://www.cnblogs.com/sunlong88/articles/9554568.html

pip3  install pipenv

  

用法

在使用pipenv之前,必须彻底的忘记pip这个东西

新建一个准备当环境的文件夹pipenvtest,并cd进入该文件夹:
pipenv --three 会使用当前系统的Python3创建环境

pipenv --python 3.6 指定某一Python版本创建环境

pipenv shell 激活虚拟环境

pipenv --where 显示目录信息
/home/jiahuan/pipenvtest

pipenv --venv 显示虚拟环境信息
/home/jiahuan/.local/share/virtualenvs/pipenvtest-9KKRH3OW

pipenv --py 显示Python解释器信息
/home/jiahuan/.local/share/virtualenvs/pipenvtest-9KKRH3OW/bin/python

pipenv install requests 安装相关模块并加入到Pipfile

pipenv install django==1.11 安装固定版本模块并加入到Pipfile

pipenv graph 查看目前安装的库及其依赖

requests==2.18.4
  - certifi [required: >=2017.4.17, installed: 2017.11.5]
  - chardet [required: <3.1.0,>=3.0.2, installed: 3.0.4]
  - idna [required: >=2.5,<2.7, installed: 2.6]
  - urllib3 [required: >=1.21.1,<1.23, installed: 1.22]

  

pipenv check检查安全漏洞

Checking PEP 508 requirements…
Passed!
Checking installed package safety…
All good! 

  

pipenv uninstall --all 卸载全部包并从Pipfile中移除

 

Found 5 installed package(s), purging…
Uninstalling certifi-2017.11.5:
  Successfully uninstalled certifi-2017.11.5
Uninstalling chardet-3.0.4:
  Successfully uninstalled chardet-3.0.4
Uninstalling idna-2.6:
  Successfully uninstalled idna-2.6
Uninstalling requests-2.18.4:
  Successfully uninstalled requests-2.18.4
Uninstalling urllib3-1.22:
  Successfully uninstalled urllib3-1.22

  

跟上面graph命令显示的内容对应

出现个报错

之后随意测试的时候 使用pipenv --two 想创建一个基于Python2.7的虚拟环境时出了点问题。报了这样一个错误
TypeError: 'NoneType' object is not subscriptable
而使用pipenv --python 3.6却没有问题(自带的是Python3.5,Python3.6新安装的,这让我很纳闷,明天去公司试一试。

经过测试:在公司ubuntu机器上可以使用 ,今晚再回家里试试...
.....
回家仔细观察了报错,原来是我pip源的配置文件出了点错,多了个空格,囧 ~
OK,那就没问题
==========================================
2018/01/24更新
pipenv install 安装模块时有时候会很慢
可以设置国内源:Pipfile文件中[source]下面url属性,比如修改成:url = "https://pypi.tuna.tsinghua.edu.cn/simple"

小结

这里写了一个pipenv常用的命令,很不错的工具,pip与virtualenv的结合体,值得一用。

 

 

 

 

 

 

 

 

 
 

本文来自博客园,作者:孙龙-程序员,转载请注明原文链接:https://www.cnblogs.com/sunlong88/articles/9629497.html

posted on 2018-09-11 18:21  孙龙-程序员  阅读(447)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3