How do I migrate my system from one that relies on Python 2.7 to one that provides the same functionality using Python 3?

谁说胖子不能爱 提交于 2019-12-23 04:26:30

问题


Currently, I use Python 2.7 as my primary Python (see configuration details below), including several crucial command line utilities such as virtualenvwrapper, and would like remove Python 2.7 and migrate my configuration entirely to Python 3.

How do I do this? The elements of such a transition are, as near as I can tell:

  • Remove Python 2.7
  • Remove Python 2.7 versions of command line tools (e.g. virtualenv, virtualenvwrapper, etc.)
  • Ensure that Python 3 is the default Python (e.g. that python invokes python3, pip invokes pip3, all Python related paths are configured for Python 3, etc.)
  • Install the Python 3 versions of packages and command line tools I rely on

Even if I've got that about right, I'm not sure how to proceed and in what order. I assume that the last item is straightforward (as long as I remember what tools I need and that they all have Python 3 versions), at least once pip invokes pip3; but beyond that I'm stumped and fear I could do serious damage by getting it wrong. For example, are there special steps necessary to ensure that my existing configurations for python are persevered and used for Python 3?

How do I migrate my system from one that relies on Python 2.7 (with Python 3 available on the side) to one that provides the same functionality using Python 3?


~ $ which -a python
/usr/local/bin/python
/usr/bin/python
~ $ which -a python2
/usr/local/bin/python2
~ $ which -a python3
/usr/local/bin/python3
~ $ which -a pip
/usr/local/bin/pip
~ $ which -a pip2
/usr/local/bin/pip2
~ $ which -a pip3
/usr/local/bin/pip3
~ $ /usr/local/bin/python --version
Python 2.7.15
~ $ /usr/bin/python --version
Python 2.7.10
~ $ /usr/local/bin/python2 --version
Python 2.7.15
~ $ /usr/local/bin/python3 --version
Python 3.7.2
~ $ /usr/local/bin/pip --version
pip 19.0.2 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
~ $ /usr/local/bin/pip2 --version
pip 19.0.2 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
~ $ /usr/local/bin/pip3 --version
pip 19.0.2 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
~ $ ls -alt /usr/local/bin/python
lrwxr-xr-x  1 Rax  admin  38 Feb 13 08:22 /usr/local/bin/python -> ../Cellar/python@2/2.7.15_3/bin/python
~ $ ls -alt /usr/bin/python      
-rwxr-xr-x  1 root  wheel  66880 Nov 30 02:38 /usr/bin/python
~ $ ls -alt /usr/local/bin/python2
lrwxr-xr-x  1 Rax  admin  39 Feb 13 08:22 /usr/local/bin/python2 -> ../Cellar/python@2/2.7.15_3/bin/python2
~ $ ls -alt /usr/local/bin/python3
lrwxr-xr-x  1 Rax  admin  36 Feb 17 17:26 /usr/local/bin/python3 -> ../Cellar/python/3.7.2_2/bin/python3
~ $ ls -alt /usr/local/bin/pip
lrwxr-xr-x  1 Rax  admin  35 Feb 13 08:22 /usr/local/bin/pip -> ../Cellar/python@2/2.7.15_3/bin/pip
~ $ ls -alt /usr/local/bin/pip2
lrwxr-xr-x  1 Rax  admin  36 Feb 13 08:22 /usr/local/bin/pip2 -> ../Cellar/python@2/2.7.15_3/bin/pip2
~ $ ls -alt /usr/local/bin/pip3
lrwxr-xr-x  1 Rax  admin  33 Feb 17 17:26 /usr/local/bin/pip3 -> ../Cellar/python/3.7.2_2/bin/pip3
~ $ env
VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
VIRTUALENVWRAPPER_PROJECT_FILENAME=.project
WORKON_HOME=/Users/Rax/Documents/Projects/Coding/Python/venvs
PROJECT_HOME=/Users/Rax/Documents/Projects/Coding/Python/projs
VIRTUALENVWRAPPER_HOOK_DIR=/Users/Rax/Documents/Projects/Coding/Python/venvs
LANG=en_US.UTF-8
PYTHONSTARTUP=/Users/Rax/Documents/Projects/Coding/Python/aldaron/shell_config.py
VIRTUALENVWRAPPER_WORKON_CD=1
...

来源:https://stackoverflow.com/questions/54738414/how-do-i-migrate-my-system-from-one-that-relies-on-python-2-7-to-one-that-provid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!