linux 下virtualenv及TensorFlow环境搭建与安装

来源:互联网 发布:织带打版软件 编辑:程序博客网 时间:2024/06/07 22:43


虚拟环境—virtualenv

我理解的虚拟环境就像是出租屋的房东,房东会提供一些基本配置,但是如果你有啥个性化需求请自行配置(话说我想买个遮阳的窗帘儿,一切都准备好了,就差资金了)。
python里的virtualenv就有这样的功效,它解决了项目A需要依赖2.Xpython,而项目B需要依赖3.Xpython这种两难问题,从而使你的全局site-package目录保持干净和可管理。
virtualenv安装

重点终于来了,本文以linux系统为例简单介绍virtualenv通过pip安装virtualenv
# pip install virtualenv

gjh@gjh-System-Product-Name:~$  pip install virtualenv
Collecting virtualenv
  Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
    100% |████████████████████████████████| 1.8MB 42kB/s
Installing collected packages: virtualenv

如果你的机子是共用的,而你的权限又不够大可是尝试下面的语句
$ pip install virtualenv --user
gjh@gjh-System-Product-Name:~$ pip install virtualenv --user
Collecting virtualenv
  Using cached virtualenv-15.1.0-py2.py3-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv-15.1.0

这样保证你的virtualenv会创建在你自己的目录下,并且创建成功后会有文件路径,一般是存在一个./local的隐形文件夹下。为了方便可以创建一个专门管理python版本的文件夹

$ mkdir pythonenv
$ cd pythonenv
$ virtualenv --system-site-package tf0.10  //创建python虚拟环境
$ source tf0.10/bin/activate   //启动python的虚拟环境,启动后命令前面就有了当前的python虚拟环境的名称 eg:(tf0.10)


上面的virtualenv –system-site-package tf0.10我没有运行成功,感觉是因为不是root权限安装没有软链到bin下的原因,所以用了下面这句话

$ .local/lib/python2.7/site-packages/virtualenv.py -p /usr/bin/python2.7 tf0.10


-p后面的是创建虚拟环境用到的python编译器,如果你用的是其他版本的python可以换成其他的
至此,virtualenv已经安装成功并且启动成功
安装TensorFlow

$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
$ pip install  $TF_BINARY_URL

gjh@gjh-System-Product-Name:~$ mkdir pythonenv
gjh@gjh-System-Product-Name:~$ cd pythonenv
gjh@gjh-System-Product-Name:~/pythonenv$  virtualenv --system-site-package tf0.10
New python executable in /home/gjh/pythonenv/tf0.10/bin/python
Installing setuptools, pip, wheel...done.
gjh@gjh-System-Product-Name:~/pythonenv$ source tf0.10/bin/activate
(tf0.10) gjh@gjh-System-Product-Name:~/pythonenv$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
(tf0.10) gjh@gjh-System-Product-Name:~/pythonenv$ pip install  $TF_BINARY_URL
Collecting tensorflow==0.10.0 from https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
/home/gjh/pythonenv/tf0.10/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/home/gjh/pythonenv/tf0.10/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl (102.0MB)
    100% |████████████████████████████████| 102.0MB 20kB/s
Requirement already satisfied: numpy>=1.8.2 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.10.0)
Requirement already satisfied: mock>=2.0.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.10.0)
Collecting protobuf==3.0.0b2 (from tensorflow==0.10.0)
/home/gjh/pythonenv/tf0.10/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading protobuf-3.0.0b2-py2.py3-none-any.whl (326kB)
    100% |████████████████████████████████| 327kB 217kB/s
Requirement already satisfied: wheel in ./tf0.10/lib/python2.7/site-packages (from tensorflow==0.10.0)
Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.10.0)
Requirement already satisfied: funcsigs>=1; python_version < "3.3" in /usr/local/lib/python2.7/dist-packages (from mock>=2.0.0->tensorflow==0.10.0)
Requirement already satisfied: pbr>=0.11 in /usr/local/lib/python2.7/dist-packages (from mock>=2.0.0->tensorflow==0.10.0)
Requirement already satisfied: setuptools in ./tf0.10/lib/python2.7/site-packages (from protobuf==3.0.0b2->tensorflow==0.10.0)
Installing collected packages: protobuf, tensorflow
  Found existing installation: protobuf 3.4.0
    Not uninstalling protobuf at /usr/local/lib/python2.7/dist-packages, outside environment /home/gjh/pythonenv/tf0.10
Successfully installed protobuf-3.0.0b2 tensorflow-0.10.0



阅读全文
0 0
原创粉丝点击