pip3安装和卸载以及常用命令

pip3安装和卸载以及常用命令,第1张

环境:centos7.6

python3版本:3.6.8

pip3版本:18.1

python3安装

注:如果安装了多个版本的pip,可执行多次卸载

重装PIP的命令:easy_inatall pip

注:默认是升级到最新版本

注:未验证

这个问题,集群中只有两个节点遇到了,通过百度可知,是少了_bz2.cpython-36m-x86_64-linux-gnu.so这个os文件,那么解决办法和上面一样从其他机器上把这个文件复制过来即可。

1、pip下载安装

1.1 pip下载

代码如下复制代码

# wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate

1.2 pip安装

代码如下复制代码

# tar -xzvf pip-1.5.4.tar.gz

# cd pip-1.5.4

# python setup.py install

2. pip使用详解

2.1 pip安装软件

代码如下复制代码

# pip install SomePackage

[...]

Successfully installed SomePackage

2.2 pip查看已安装的软件

代码如下复制代码

# pip show --files SomePackage

Name: SomePackage

Version: 1.0

Location: /my/env/lib/pythonx.x/site-packages

Files:

../somepackage/__init__.py

[...]

2.3 pip检查哪些软件需要更新

代码如下复制代码

# pip list --outdated

SomePackage (Current: 1.0 Latest: 2.0)

2.4 pip升级软件

代码如下复制代码

# pip install --upgrade SomePackage

[...]

Found existing installation: SomePackage 1.0

Uninstalling SomePackage:

Successfully uninstalled SomePackage

Running setup.py install for SomePackage

Successfully installed SomePackage

2.5 pip卸载软件

代码如下复制代码

$ pip uninstall SomePackage

Uninstalling SomePackage:

/my/env/lib/pythonx.x/site-packages/somepackage

Proceed (y/n)? y

Successfully uninstalled SomePackage

安装tensorflow

pip install --upgrade https://storage.googleapis.com/tensorflow/Linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

错误:oserror no such file or directory site-packages/setuptools-21.0.0-py2.7.egg

解决:pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

--ignore-installed

Python 2.7.3 (default, Apr 26 2016, 11:18:30)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>>import tensorflow as tf

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module>

from tensorflow.python import *

File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 45, in <module>

from tensorflow.python import pywrap_tensorflow

File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>

_pywrap_tensorflow = swig_import_helper()

File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper

_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)

ImportError: /lib64/libc.so.6: version `GLIBC_2.15' not found (required by /usr/local/python27/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so)

tensorflow0.80版本编译的时候使用GLIBC_2.15,系统自带的是GLIBC_2.12,所以报错了。

安装新版glibc

1.glibc下载

从http://www.gnu.org/software/libc/ 下载源代码。我下载的版本是2.20,链接地址是http://ftp.gnu.org/gnu/glibc/glibc-2.20.tar.gz

2.安装

因为glibc库使用广泛,为了避免污染当前系统环境,最好自定义安装目录,使用时定义一下环境变量就行了。具体步骤如下:

我使用的法(直接升级glibc):

wget http://ftp.gnu.org/pub/gnu/glibc/glibc-2.17.tar.xz

xz -d glibc-2.17.tar.xz

tar -xvf glibc-2.17.tar

cd glibc-2.17

mkdir build

cd build

../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin

make &&make install

需要等大概10分钟。

输入strings /lib64/libc.so.6|grep GLIBC发现已经更新

Python 2.7.3 (default, Apr 26 2016, 11:18:30)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>>import tensorflow as tf

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module>

from tensorflow.python import *

File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 45, in <module>

from tensorflow.python import pywrap_tensorflow

File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>

_pywrap_tensorflow = swig_import_helper()

File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper

_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)

ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by /usr/local/python27/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so)

没有GLIBCXX_3.4.14版本支持,继续安装(注意:libstdc++6_4.7.2-5_amd64.deb这是64位,libstdc++6_4.7.2-5_i386.deb这个是32位)

下载新版本,地址:http://ftp.de.debian.org/debian/pool/main/g/gcc-4.7/libstdc++6_4.7.2-5_amd64.deb

ar -x libstdc++6_4.7.2-5_amd64.deb&&tar xvf data.tar.gz

#cd /root/usr/lib/x86_64-linux-gnu

#ll

lrwxrwxrwx 1 root root 19 Apr 26 15:21 libstdc++.so.6 ->libstdc++.so.6.0.17

-rw-r--r-- 1 root root 991600 Jan 7 2013 libstdc++.so.6.0.17

# find / -name libstdc++.so.6

/usr/lib64/libstdc++.so.6

/root/usr/lib/x86_64-linux-gnu/libstdc++.so.6

#mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak

#cp libstdc++.so.6.0.17 /usr/lib64/

#cd /usr/lib64/

#chmod +x libstdc++.so.6.0.17

#ll libstdc++.so.6.0.17

-rwxr-xr-x 1 root root 991600 Apr 26 15:30 libstdc++.so.6.0.17

#ln -s libstdc++.so.6.0.17 libstdc++.so.6

>>>import tensorflow as tf

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module>

from tensorflow.python import *

File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 45, in <module>

from tensorflow.python import pywrap_tensorflow

File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>

_pywrap_tensorflow = swig_import_helper()

File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper

_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)

ImportError: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.19' not found (required by /usr/local/python27/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so)

从网上下载libstdc++.so.6.0.20

http://ftp.de.debian.org/debian/pool/main/g/gcc-4.8/

或者

http://download.csdn.net/detail/pomelover/7524227

放到/usr/lib64/下

#chmod +x libstdc++.so.6.0.20

#rm libstdc++.so.6

#ln -s libstdc++.so.6.0.20 libstdc++.so.6

#strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX

ImportError: cannot import name pywrap_tensorflow

edit: The real fix for me was to updated setuptools to the latest and it allowed me to upgrade mock and six to the latest. I was on setuptools 3.3. In my case I also had to remove said modules by hand because they were owned by OS in '/usr/local/lib/python2.7/dist-packages/'

check versions of everything

pip freeze | grep -e six -e mock

easy_install --version

Update everything

wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python

pip install mock --upgrade

pip install six --upgrade

终于成功了。

>>>import tensorflow as tf

>>>hello = tf.constant('Hello, TensorFlow!')

>>>sess = tf.Session()

>>>sess.run(hello)

Hello, TensorFlow!

>>>a = tf.constant(10)

>>>b = tf.constant(32)

>>>sess.run(a+b)

42

>>>

>>>print product

Tensor("MatMul:0", shape=(1, 1), dtype=float32)

>>>sess = tf.Session()

>>>result = sess.run(product)

>>>print result

[[ 12.]]

>>>sess.close()

>>>exit()


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8444440.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-16
下一篇 2023-04-16

发表评论

登录后才能评论

评论列表(0条)

保存