解决由于 Python 版本重复而导致的错误

解决由于 Python 版本重复而导致的错误

我从主目录中通过 tar 安装了 python3.5.2。(我记得使用了 atlinstall 命令)

然后,我使用 pip3 安装了 django,通过执行sudo -H pip3 install django,安装成功。

我还安装了 numpy、scipy 和一些其他模块。

当我python3.5从命令行使用命令时,所有这些模块都是可访问的,但是当我调用时,我无法导入这些模块python3

而且,所有第三方软件也都在使用这个python3,因此我无法使用任何 GUI 来导入任何提到的模块。

我的问题是,如何让另一个 python3 指向与python3.5安装了所有模块的相同的东西。

salman@Skynet ~]$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'django'
>>> exit()
[salman@Skynet ~]$ python3.5
Python 3.5.2 (default, Nov 30 2016, 11:30:08)   
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> 

python3.5用的时候才有效。

编辑:请求的输出

which python3 python3.5

/usr/bin/python3
/usr/local/bin/python3.5

env | grep -i python; for p in $(ls /usr{,/local}/bin/python3*); do echo -- $(ls -l $p); $p -c "import sys; print(sys.path)"; done

-- lrwxrwxrwx 1 root root 9 Mar 23 2016 /usr/bin/python3 -> python3.5
    ['', '/usr/lib/python35.zip', '/usr/lib/python3.5',  '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-  dynload', '/usr/local/lib/python3.5/dist-packages',  '/usr/lib/python3/dist-packages']
-- -rwxr-xr-x 2 root root 4460336 Nov 18 01:23 /usr/bin/python3.5
    ['', '/usr/lib/python35.zip', '/usr/lib/python3.5',  '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib- dynload', '/usr/local/lib/python3.5/dist-packages',   '/usr/lib/python3/dist-packages']
-- -rwxr-xr-x 2 root root 4460336 Nov 18 01:23 /usr/bin/python3.5m
    ['', '/usr/lib/python35.zip', '/usr/lib/python3.5',  '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib- dynload', '/usr/local/lib/python3.5/dist-packages',   '/usr/lib/python3/dist-packages']
-- lrwxrwxrwx 1 root root 10 Mar 23 2016 /usr/bin/python3m ->  python3.5m
    ['', '/usr/lib/python35.zip', '/usr/lib/python3.5',  '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib- dynload', '/usr/local/lib/python3.5/dist-packages',  '/usr/lib/python3/dist-packages']
-- -rwxr-xr-x 2 root root 12170760 Nov 30 11:30   /usr/local/bin/python3.5
    ['', '/usr/local/lib/python35.zip', '/usr/local/lib/python3.5',  '/usr/local/lib/python3.5/plat-linux', '/usr/local/lib/python3.5/lib- dynload', '/usr/local/lib/python3.5/site-packages']
-- -rwxr-xr-x 2 root root 12170760 Nov 30 11:30  /usr/local/bin/python3.5m
    ['', '/usr/local/lib/python35.zip', '/usr/local/lib/python3.5',  '/usr/local/lib/python3.5/plat-linux', '/usr/local/lib/python3.5/lib- dynload', '/usr/local/lib/python3.5/site-packages']
-- -rwxr-xr-x 1 root root 3080 Nov 30 11:31  /usr/local/bin/python3.5m-config
Usage: /usr/local/bin/python3.5m-config --prefix|--exec-prefix|--  includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--    configdir

另外,如何才能从中删除 python3.5/usr/local/bin而不损害 中的 python3 呢/usr/bin

感谢大家阅读问题并回答。

答案1

一个解决方案 —— 尽管需要仔细考虑 —— 是指向python3哪个python3.5正常工作:

sudo mv /usr/bin/python3 /usr/bin/python3_backup
sudo ln -s /usr/local/bin/python3.5 /usr/bin/python3 

更新:其他方法

我的第一个答案是,如果你确定你需要 python3.5 /usr/local/bin。如果不是这种情况,并且你想在从/usr/localpython3.5 添加模块的同时保留系统 python 3,那么你可以在 bashrc 中按如下方式更新PYTHON_PATH变量(根据你提供的输出):

export PYTHONPATH=${PYTHONPATH}:/usr/local/lib/python3.5:/usr/local/lib/python3.5/plat-linux:/usr/local/lib/python3.5/site-packages

相关内容