I have a folder. Inside of this folder is an executable called python
. When I try to run python
from the terminal it instead runs the python interpreter. How can I run the file called python?
-
1Close voters: This is a very different question than "how do I add a directory to my path" although the answers to that may help here.– SethJan 20, 2015 at 15:45
2 Answers
Specify the path. If you're in the directory with the binary, that's as simple as:
./python
Or yes, do as Muru suggested and add it to the path. That said, changing the path could interfere with how applications (running under your user) call Python. If you deflect them to the wrong version, they may function incorrectly.
There is not a good way to override the global python
.
It should point to the version that ships with Ubuntu.
-
rather confused about your last comment. Virtualenv is a great way to override the global python– FoonJan 19, 2015 at 1:14
-
virtualenv
path replacements are temporary though. You load them up for your session and then you deactivate them. They shouldn't affect things in other sessions.– Oli ♦Jan 19, 2015 at 1:16
Along with the other answers you can also use the full path to the executable. For example, if your python executable is in /home/user/some_dir/python then running the following command from in the terminal will do the job:
user@user-home:~$ /home/user/some_dir/python
For ease of use you can create an alias for the above command so that you don't have to type the full path every time, by just appending the it in your .bashrc file. To do so, run the following commands in the terminal:
user@user-home:~$ echo "alias local_python=/home/user/some_dir/python" >> /home/user/.bashrc
user@user-home:~$ source /home/user/.bashrc
****Important note: Here i have used local_python as the alias name, you can choose any name you want but don't use python or any other already installed binaries' names as name of the alias.