1. sudo apt-get install python3,也可以指定具体版本。
安装成功后,
work@ubuntu:~$ python -V Python 2.7.12 work@ubuntu:~$ python3 -V Python 3.5.2 work@ubuntu:~$ pip -V 程序“pip”尚未安装。 您可以使用以下命令安装: sudo apt install python-pip work@ubuntu:~$ pip3 -version 程序“pip3”尚未安装。 您可以使用以下命令安装: sudo apt install python3-pip
2.将python命令指向python3
work@ubuntu:~$ python -V Python 2.7.12 work@ubuntu:~$ which python /usr/bin/python
### 将原来的python文件进行备份 work@ubuntu:~$ sudo cp /usr/bin/python /usr/bin/python_bak [sudo] work 的密码:? work@ubuntu:~$ sudo ln -s /usr/bin/python3.5 /usr/bin/python ln: 无法创建符号链接'/usr/bin/python': 文件已存在
### 删除原来指向python2的文件
work@ubuntu:~$ sudo rm /usr/bin/python
###?重新指向python3版本 work@ubuntu:~$ sudo ln -s /usr/bin/python3.5 /usr/bin/python work@ubuntu:~$ python -V Python 3.5.2 work@ubuntu:~$ which python /usr/bin/python
3. 安装pip:
work@ubuntu:~$ pip3 -V 程序“pip3”尚未安装。 您可以使用以下命令安装: sudo apt install python3-pip work@ubuntu:~$ sudo apt-get install python3-pip work@ubuntu:~$ pip3 -V pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5) 先安装numpy试一下,
work@ubuntu:~$ pip3 install numpy Collecting numpy ? Using cached https://files.pythonhosted.org/packages/64/4a/b008d1f8a7b9f5206ecf70a53f84e654707e7616a771d84c05151a4713e9/numpy-1.22.3.zip ? ? Complete output from command python setup.py egg_info: ? ? Traceback (most recent call last): ? ? ? File "<string>", line 1, in <module> ? ? ? File "/tmp/pip-build-pmwq861v/numpy/setup.py", line 59 ? ? ? ? raise RuntimeError(f'Cannot parse version {FULLVERSION}') ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?^ ? ? SyntaxError: invalid syntax ? ?? ? ? ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-pmwq861v/numpy/ You are using pip version 8.1.1, however version 22.0.4 is available. You should consider upgrading via the 'pip install --upgrade pip' command.
执行“pip3 install --upgrade pip”,即可。
但是提示语法问题,是因为python版本和numpy版本不匹配造成的,解决办法,要么升级python版本,要么找低版本的numpy.
网络找到解决方法:命令:curl?-fsSL -o- https://bootstrap.pypa.io/pip/3.5/get-pip.py | python3.5
work@ubuntu:~/Downloads$ curl -fsSL -o- https://bootstrap.pypa.io/pip/3.5/get-pip.py | python3.5 程序“curl”尚未安装。 您可以使用以下命令安装: sudo apt install curl work@ubuntu:~/Downloads$ pip3 install curl Traceback (most recent call last): ? File "/home/work/.local/bin/pip3", line 7, in <module> ? ? from pip._internal.cli.main import main ? File "/home/work/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 57 ? ? sys.stderr.write(f"ERROR: {exc}") ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?^ SyntaxError: invalid syntax
说明:pip3有问题。 work@ubuntu:~/Downloads$ sudo apt install curl 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 ? ? ?? 正在读取状态信息... 完成 ? ? ?? 将会同时安装下列软件: ? libcurl3-gnutls 下列【新】软件包将被安装: ? curl 下列软件包将被升级: ? libcurl3-gnutls 升级了 1 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 519 个软件包未被升级。 需要下载 328 kB 的归档。 解压缩后会消耗 353 kB 的额外空间。 您希望继续执行吗? [Y/n] y 获取:1 http://security.ubuntu.com/ubuntu xenial-security/main amd64 libcurl3-gnutls amd64 7.47.0-1ubuntu2.19 [189 kB] 获取:2 http://security.ubuntu.com/ubuntu xenial-security/main amd64 curl amd64 7.47.0-1ubuntu2.19 [139 kB] 已下载 328 kB,耗时 10秒 (30.3 kB/s) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? (正在读取数据库 ... 系统当前共安装有 265104 个文件和目录。) 正准备解包 .../libcurl3-gnutls_7.47.0-1ubuntu2.19_amd64.deb ?... 正在将 libcurl3-gnutls:amd64 (7.47.0-1ubuntu2.19) 解包到 (7.47.0-1ubuntu2.11) 上 ... 正在选中未选择的软件包 curl。 正准备解包 .../curl_7.47.0-1ubuntu2.19_amd64.deb ?... 正在解包 curl (7.47.0-1ubuntu2.19) ... 正在处理用于 libc-bin (2.23-0ubuntu10) 的触发器 ... 正在处理用于 man-db (2.7.5-1) 的触发器 ... 正在设置 libcurl3-gnutls:amd64 (7.47.0-1ubuntu2.19) ... 正在设置 curl (7.47.0-1ubuntu2.19) ... 正在处理用于 libc-bin (2.23-0ubuntu10) 的触发器 ... work@ubuntu:~/Downloads$ curl -fsSL -o- https://bootstrap.pypa.io/pip/3.5/get-pip.py | python3.5 DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality. Defaulting to user installation because normal site-packages is not writeable Collecting pip<21.0 ? Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB) ? ? ?|████████████████████████████████| 1.5 MB 305 kB/s? Installing collected packages: pip ? Attempting uninstall: pip ? ? Found existing installation: pip 22.0.4 ? ? Uninstalling pip-22.0.4: ? ? ? Successfully uninstalled pip-22.0.4 Successfully installed pip-20.3.4 work@ubuntu:~/Downloads$ pip -V pip 20.3.4 from /home/work/.local/lib/python3.5/site-packages/pip (python 3.5) work@ubuntu:~/Downloads$ pip install numpy DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality. Defaulting to user installation because normal site-packages is not writeable Collecting numpy ? Downloading numpy-1.18.5-cp35-cp35m-manylinux1_x86_64.whl (19.9 MB) ? ? ?|████████████████████████████████| 19.9 MB 965 kB/s? Installing collected packages: numpy Successfully installed numpy-1.18.5
问题解决。work@ubuntu:~/Downloads$ pip install matplotlib
work@ubuntu:~/Downloads$ pip install pyqtgraph ?
|