如何在 ubuntu 上将我的 python 版本从 3.7.5 降级到 3.6.5
How do I downgrade my version of python from 3.7.5 to 3.6.5 on ubuntu
所以目前,我有 ubuntu 19。它默认带有 python 3.7.5。我需要降级到 3.6.5。
编辑:
我正在使用 virtualenv
您还可以使用 virtualenv 来使用不同的 Python 环境。
如果您键入 python 并按 Tab 键两次左右,您可能会看到许多 Python 版本可用。我这样说是因为当我输入
python3.6 -V
我有
Python 3.6.9
可用。 python 的别名是 3.7.5
当您键入 python 时,您可能指的是 .bashrc
中定义的别名
下面讨论从 3.6.7 升级到 3.7.0,但您可以使用相同的过程进行降级。你不应该改变系统 python 除非你真的知道你在做什么
首先安装Pyenv
Installlation Instructions are here
查看 Pyenv 选项
$ pyenv
pyenv 1.2.14
Usage: pyenv <command> [<args>]
Some useful pyenv commands are:
commands List all available pyenv commands
activate Activate virtual environment
commands List all available pyenv commands
deactivate Deactivate virtual environment
doctor Verify pyenv installation and deevlopment tools to build pythons.
exec Run an executable with the selected Python version
global Set or show the global Python version
help Display help for a command
hooks List hook scripts for a given pyenv command
init Configure the shell environment for pyenv
install Install a Python version using python-build
local Set or show the local application-specific Python version
prefix Display prefix for a Python version
rehash Rehash pyenv shims (run this after installing executables)
root Display the root directory where versions and shims are kept
shell Set or show the shell-specific Python version
shims List existing pyenv shims
uninstall Uninstall a specific Python version
--version Display the version of pyenv
version Show the current Python version and its origin
version-file Detect the file that sets the current pyenv version
version-name Show the current Python version
version-origin Explain how the current Python version is set
versions List all Python versions available to pyenv
virtualenv Create a Python virtualenv using the pyenv-virtualenv plugin
virtualenv-delete Uninstall a specific Python virtualenv
virtualenv-init Configure the shell environment for pyenv-virtualenv
virtualenv-prefix Display real_prefix for a Python virtualenv version
virtualenvs List all Python virtualenvs found in `$PYENV_ROOT/versions/*'.
whence List all Python versions that contain the given executable
which Display the full path to an executable
See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme
查看 Python 版本
$ pyenv versions
system
* 3.6.7 (set by /home/taarimalta/.pyenv/version)
安装新的 Python
$ pyenv install 3.7.0
Installing Python-3.7.0...
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?
Installed Python-3.7.0 to /home/taarimalta/.pyenv/versions/3.7.0
如果您 运行 遇到 _ctypes 安装 libffi-dev 库的问题
现在看看版本
$ pyenv versions
system
* 3.6.7 (set by /home/taarimalta/.pyenv/version)
3.7.0
Select 本地环境 3.7.0
$ pyenv local 3.7.0
看到版本变了
$ pyenv versions
system
3.6.7
* 3.7.0 (set by /home/taarimalta/.python-version)
$ python
Python 3.7.0 (default, Jan 1 2020, 10:52:57)
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
切换到不同的文件夹
cd ../project2
pyenv versions
system
* 3.6.7 (set by /home/taarimalta/.pyenv/version)
3.7.0
此处的python版本可能会有所不同,具体取决于您在本地设置的python版本
全局设置pyenv版本
这会为用户全局设置 python 版本
pyenv global 3.7.0
请注意,pyenv 通过添加 .python-version 文件来设置本地版本
$ pyenv local 3.7.0
$ cat .python-version
3.7.0
注意pyenv通过查看~/.pyenv/version
文件知道全球版本
cat ~/.pyenv/version
3.8.2
从预编译的 Ubuntu deb 包 repos 安装它。
$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
出现提示时,按 ENTER 键继续。
sudo apt install python3.6
所以目前,我有 ubuntu 19。它默认带有 python 3.7.5。我需要降级到 3.6.5。
编辑:
我正在使用 virtualenv
您还可以使用 virtualenv 来使用不同的 Python 环境。
如果您键入 python 并按 Tab 键两次左右,您可能会看到许多 Python 版本可用。我这样说是因为当我输入
python3.6 -V
我有
Python 3.6.9
可用。 python 的别名是 3.7.5
当您键入 python 时,您可能指的是 .bashrc
中定义的别名下面讨论从 3.6.7 升级到 3.7.0,但您可以使用相同的过程进行降级。你不应该改变系统 python 除非你真的知道你在做什么
首先安装Pyenv
Installlation Instructions are here
查看 Pyenv 选项
$ pyenv
pyenv 1.2.14
Usage: pyenv <command> [<args>]
Some useful pyenv commands are:
commands List all available pyenv commands
activate Activate virtual environment
commands List all available pyenv commands
deactivate Deactivate virtual environment
doctor Verify pyenv installation and deevlopment tools to build pythons.
exec Run an executable with the selected Python version
global Set or show the global Python version
help Display help for a command
hooks List hook scripts for a given pyenv command
init Configure the shell environment for pyenv
install Install a Python version using python-build
local Set or show the local application-specific Python version
prefix Display prefix for a Python version
rehash Rehash pyenv shims (run this after installing executables)
root Display the root directory where versions and shims are kept
shell Set or show the shell-specific Python version
shims List existing pyenv shims
uninstall Uninstall a specific Python version
--version Display the version of pyenv
version Show the current Python version and its origin
version-file Detect the file that sets the current pyenv version
version-name Show the current Python version
version-origin Explain how the current Python version is set
versions List all Python versions available to pyenv
virtualenv Create a Python virtualenv using the pyenv-virtualenv plugin
virtualenv-delete Uninstall a specific Python virtualenv
virtualenv-init Configure the shell environment for pyenv-virtualenv
virtualenv-prefix Display real_prefix for a Python virtualenv version
virtualenvs List all Python virtualenvs found in `$PYENV_ROOT/versions/*'.
whence List all Python versions that contain the given executable
which Display the full path to an executable
See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme
查看 Python 版本
$ pyenv versions
system
* 3.6.7 (set by /home/taarimalta/.pyenv/version)
安装新的 Python
$ pyenv install 3.7.0
Installing Python-3.7.0...
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?
Installed Python-3.7.0 to /home/taarimalta/.pyenv/versions/3.7.0
如果您 运行 遇到 _ctypes 安装 libffi-dev 库的问题
现在看看版本
$ pyenv versions
system
* 3.6.7 (set by /home/taarimalta/.pyenv/version)
3.7.0
Select 本地环境 3.7.0
$ pyenv local 3.7.0
看到版本变了
$ pyenv versions
system
3.6.7
* 3.7.0 (set by /home/taarimalta/.python-version)
$ python
Python 3.7.0 (default, Jan 1 2020, 10:52:57)
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
切换到不同的文件夹
cd ../project2
pyenv versions
system
* 3.6.7 (set by /home/taarimalta/.pyenv/version)
3.7.0
此处的python版本可能会有所不同,具体取决于您在本地设置的python版本
全局设置pyenv版本
这会为用户全局设置 python 版本
pyenv global 3.7.0
请注意,pyenv 通过添加 .python-version 文件来设置本地版本
$ pyenv local 3.7.0
$ cat .python-version
3.7.0
注意pyenv通过查看~/.pyenv/version
文件知道全球版本
cat ~/.pyenv/version
3.8.2
从预编译的 Ubuntu deb 包 repos 安装它。
$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
出现提示时,按 ENTER 键继续。
sudo apt install python3.6