Python没有安装名为" python"的可执行文件在安装目录

时间:2017-03-26 21:52:55

标签: python python-3.x pip digital-ocean python-install

我正在使用DigitalOcean的Droplet:

是CentOS7 x64

我想安装python v 3.5.3并在键入' python'

时运行

我使用此页面作为参考:

https://www.digitalocean.com/community/tutorials/how-to-set-up-python-2-7-6-and-3-3-3-on-centos-6-4

我做了以下下载和编译python:

sudo yum group install "development tools"

作为本地用户乔:

cd ~
wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tgz
tar zxfv Python-3.5.3.tgz
find ~/python -type d | xargs chmod 0755
cd Python-3.5.3
./configure --prefix=/usr/local
make
sudo make altinstall

/ usr / local / bin如下所示:

-rwxr-xr-x 1 root root      101 Mar 26 21:20 /usr/local/bin/2to3-3.5
-rwxr-xr-x 1 root root      242 Mar 26 21:20 /usr/local/bin/easy_install-3.5
-rwxr-xr-x 1 root root       99 Mar 26 21:20 /usr/local/bin/idle3.5
-rwxr-xr-x 1 root root      214 Mar 26 21:20 /usr/local/bin/pip3.5
-rwxr-xr-x 1 root root       84 Mar 26 21:20 /usr/local/bin/pydoc3.5
-rwxr-xr-x 2 root root 12309712 Mar 26 21:19 /usr/local/bin/python3.5
-rwxr-xr-x 2 root root 12309712 Mar 26 21:19 /usr/local/bin/python3.5m
-rwxr-xr-x 1 root root     3080 Mar 26 21:20 /usr/local/bin/python3.5m-config
-rwxr-xr-x 1 root root      236 Mar 26 21:20 /usr/local/bin/pyvenv-3.5

没有' python'仅可执行文件' python3.5'唯一的' python'可执行文件位于

/home/joe/Python-3.5.3

-rwxrwxr-x  1 bucket bucket 12309712 Mar 26 21:16 python

它的大小相同,所以它可能是同一个文件。我应该在/ usr / local / bin中创建一个名为python3的python指向链接的符号链接吗?我觉得这有点像黑客,但我看不出我做错了什么。

另外,我不能打电话给pip。

我试图安装它:

wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py -O - | python3.5 - --user
--2017-03-26 21:47:19--  https://bootstrap.pypa.io/get-pip.py
Resolving bootstrap.pypa.io (bootstrap.pypa.io)... 151.101.0.175, 151.101.192.175, 151.101.64.175, ...
Connecting to bootstrap.pypa.io (bootstrap.pypa.io)|151.101.0.175|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1595408 (1.5M) [text/x-python]
Saving to: ‘STDOUT’

100%[=======================================================================================================>] 1,595,408   --.-K/s   in 0.08s   

2017-03-26 21:47:19 (19.6 MB/s) - written to stdout [1595408/1595408]

Requirement already up-to-date: pip in /usr/local/lib/python3.5/site-packages
[bucket ~]$ pip
-bash: pip: command not found

感谢。

2 个答案:

答案 0 :(得分:0)

用Python 3.5二进制文件替换/覆盖python二进制文件(我认为是Python 2.7)并不是一个好主意。这反过来意味着系统上的所有内容现在都将使用您的新解释器 - 并且可能会中断。事实上,Debian已经认为" python"将始终引用Python 2.7。

更好 - 更安全 - 更新程序以使用python3.5二进制文件的想法。

或使用virtualenv。

答案 1 :(得分:0)

我要感谢Penguin Brian和abccd对virtualenv的建议。它允许我设置一个本地' python'可执行文件。我安装了它并设置了一个有效的virtualenv。

sudo yum groupinstall "Development tools"
sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

cd /usr/local/src
sudo wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tar.xz --no-check-certificate
sudo tar xf Python-3.5.3.tar.xz
cd Python-3.5.3
sudo ./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
sudo make
sudo make altinstall

sudo pip3.5 install virtualenv
sudo pip3.5 install virtualenvwrapper

作为本地用户:

mkdir ~/Envs

将以下行添加到.bashrc

export WORKON_HOME=$HOME/Envs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.5
source /usr/local/bin/virtualenvwrapper.sh

保存文件,然后:

source ~/.bashrc

mkvirtualenv <yourname>

当您重新登录以访问virtualenv时:

$workon <yourname>
(yourname)$ python --version
Python 3.5.3