11/18/2023 0 Comments Run python terminalYou can also just edit the program and change the shebang: #!/usr/bin/python2 You can override the shebang when calling the app as interpreter app: $ python2 `which app_name` The shebang just tells the shell to call the script using the given interpreter. Other Linux distributions probably have something like this. While this does not really answer your question - because it affects every window and avery other user in the system - I'm mentioning it for the sake of completeness.įor example, if you are using Ubuntu you can change the default python interpreter using: $ update-alternatives -config python The bossy way: change the default Python version system-wide Personally, I would change it to the canonical form and send a pull request to the author of the 3rd-party app. In this case, none of the previous tricks would work. For example, suppose the first line of the program is: #!/usr/bin/python Perhaps the app author did not follow the best practices and hardcoded the Python path in the shebang. The positive karma way: if the 3rd-party app has a hardcoded path in the shebang Now the default is the version you want: $ env python -version Then every time you want to make python2 the default, do: $ export PATH=~/local/python2/:$PATH $ ln -s `which python2` ~/local/python2/python Make a local copy of the python you want to make the default temporarily (you just have to do this one time): $ mkdir ~/local For example, suppose the default python interpreter is not the one you want: $ env python -version If the 3rd-party app you are running follows this convention, you can change the PATH. It is a best practice to write the shebang for Python scripts like: #!/usr/bin/env python Looks like it is getting popular.īoth are elegant, easy to use and a perfect fit for this use case (switch to a particular python version in a terminal window temporarily). This project was forked from rbenv and ruby-build, and modified for Python". Quoting the project readme, "It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. There is another tool called pyenv that lets you easily switch between multiple versions of Python. Then you can switch temporarily to python2 by typing: workon py2 Gosh, you can make one for each Python project! mkvirtualenv p圓 Now you can make a virtual environment for each version of Python. Then I add a line like the following one to my shell profile: source /usr/local/bin/virtualenvwrapper.sh Usually I install it using: sudo pip install virtualenvwrapper I like to use a sugary wrapper around it called virtualenvwrapper. The most used tool for keeping multiple Python environments is virtualenv.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |