美文网首页
Ubuntu下Python3.8.2安装虚拟环境virtuale

Ubuntu下Python3.8.2安装虚拟环境virtuale

作者: 寽虎非虫003 | 来源:发表于2020-04-17 10:50 被阅读0次

前情提要

系统为Ubuntu16.04。
安装成功Python3.8.2及pip在上一篇简书:Ubuntu install Python later than it with OS,Ubuntu安装Python更高版本

特别说明

自信自己之前安装没有问题的同学可以直接去参考How to Create Python Virtual Environment on Ubuntu 18.04 & 16.04使用 pip 安装 TensorFlow,本文比较长的原因是出现了很多错误并记录,经验证,参考网页的安装完全没有问题。

本次安装

检查pip3.8:

#无效操作,因为原本的Python2.7和Python3.5.2还没有安装pip
which pip
which pip3

#实测有效操作
 which pip3.8

输出为:

/usr/local/bin/pip3.8

安装虚拟环境virtualenv尝试

参考How to Create Python Virtual Environment on Ubuntu 18.04 & 16.04使用 pip 安装 TensorFlow进行安装。
代码如下:

sudo pip3.8 install virtualenv
#或者
sudo pip3.8 install -U virtualenv

一个小插曲

输出

ERROR: Command errored out with exit status 1:
#中间一大堆红字…………
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

pip更新

输入

pip3.8 install --upgrade pip

输出

ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/bin/pip3.8'
Consider using the `--user` option or check the permissions.

解决:

pip3.8 install --upgrade pip --user

成功

继续安装virtualenv

pip3.8 install virtualenv

这次比较顺利。

创建虚拟环境

virtualenv --system-site-packages -p /usr/local/bin/python3.8 virPy   #创建虚拟环境
source ./virPy/bin/activate #激活虚拟环境

一个大插曲

安装虚拟环境virtualenv尝试

参考How to Create Python Virtual Environment on Ubuntu 18.04 & 16.04使用 pip 安装 TensorFlow进行安装。
代码如下:

sudo pip3.8 install virtualenv
#或者
sudo pip3.8 install -U virtualenv

然后,出现报错,为保护隐私,设计用户名的地方将用***或者 username进行处理:

WARNING: The directory '/home/username/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: The directory '/home/username/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting virtualenv
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
  Could not fetch URL https://pypi.org/simple/virtualenv/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/virtualenv/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
  ERROR: Could not find a version that satisfies the requirement virtualenv (from versions: none)
ERROR: No matching distribution found for virtualenv
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

第一次尝试处理

参考The directory or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. #988,如下:

sudo -H pip3.8 install virtualenv

报错的后半部分没有变,前半部分变成了如下:

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

经过多方查证,是ssl不对,参考sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev
libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
和[ “ssl module in Python is not available” when installing package with pip3
然后回去检查我的安装步骤,发现复制如下语句时由于一次复制多句导致实际只执行了第一句:

sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev \
   libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev

导致了依赖库的缺失,也就是说前情提要里面的安装是完全正确的。

插曲总结

复制网页上的代码的时候一定要注意复制的是不是和实际运行的一样,有时候有的网页上的会多一些版权信息,有时候比如这次,由于没留意到换行,导致了依赖库的缺失。

全文完。

相关文章

网友评论

      本文标题:Ubuntu下Python3.8.2安装虚拟环境virtuale

      本文链接:https://www.haomeiwen.com/subject/bkpsvhtx.html