The Wayback Machine - https://web.archive.org/web/20210119191320/https://github.com/realpython/python-guide/pull/1010
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lines 123 to 127 #1010

Closed
wants to merge 1 commit into from
Closed

Added lines 123 to 127 #1010

wants to merge 1 commit into from

Conversation

@mkrajaci
Copy link

@mkrajaci mkrajaci commented Aug 31, 2019

I was installing Python today with this tutorial and after instaling Python, python --version still pointed to Python 2. I added an alias to my .bash_profile file to point it to Python 3.

I was installing Python today with this tutorial and after instaling Python, python --version still pointed to Python 2. I added an alias to my .bash_profile file to point it to Python 3.
@mkrajaci
Copy link
Author

@mkrajaci mkrajaci commented Jan 14, 2020

@dbader Hey Dane, can you check this PR opened a long time ago?

@bzaczynski
Copy link
Contributor

@bzaczynski bzaczynski commented Aug 4, 2020

Hey, Mario. Thanks for submitting your PR! And sorry for taking so long to respond.

Aliasing isn't perfect because it conflicts with virtual environments. If you define an alias, it'll silently take precedence over an active environment:

$ python -m venv env
$ . env/bin/activate
(env) $ which python
/home/jdoe/project/env/bin/python
(env) $ python --version
Python 3.8.0
(env) $ alias python=/usr/bin/python2.7
(env) $ python --version
Python 2.7.17
(env) $ which python
/home/jdoe/project/env/bin/python  # <- Python 3.8
(env) $ $(which python) --version
Python 3.8.0

If that's not confusing enough, other commands would also require aliasing. Setting an alias just for the python command won't change the pip one, for example:

(env) $ alias python=/usr/bin/python2.7
(env) $ python --version
Python 2.7.17
(env) $ pip --version
pip 19.2.3 from /home/jdoe/project/env/lib/python3.8/site-packages/pip (python 3.8)

A safer bet would be to stick to the virtual environments or use pyenv to manage the installed Python versions.

@bzaczynski bzaczynski closed this Aug 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.