Adding Python 3.11 to `$PATH`
Hi, I'm new here. So basically I builded Python 3.11 (https://python.org/) from source (from GitHub python/cpython branch "3.11"). So, here what I did : (obviously first I downloaded the repo as ZIP)
cd Downloads
7z x cpython-3.11.zip
cd cpython-3.11
chmod +x configure
./configure
make
Everything is okay, I can run Python 3.11 only in the directory because it is not added to $PATH
.
And here is the problem.
What I tried :
- Rename the file
~/cpython-3.11/python
to~/cpython-3.11/python3.11
- Open the
.bashrc
file located in /home/[username]/ - Added that line of code at the end :
export PATH="/home/hg/cpython-3.11/python3.11:$PATH
Note that my user name is hg
(HGStyle).
So I restarted my terminal and it does not work.
Can someone help please ?
I tried to do the same thing on the .profile
file but it still does not work. I tried to remove the quote marks but it still does not work.
1 answer
There are two possible issues that I can see.
First, as already brought up in a comment thread, it appears that the export
command you added in your .bashrc
is missing a final "
. This should cause an error message to be printed when starting a shell, making it an easy error to spot.
Second and more likely to be the problem, $PATH
points to directories to search for executable files; it does not point directly at specific executable files. So if you have a python
binary originally in the directory ~/cpython-3.11
, then within that directory do a mv python python3.11
, then want to be able to start it by giving only its name (not a full path) you will need to add the directory it is in (~/cpython-3.11
) to your $PATH
.
Therefore, you should probably use something like
export PATH="~/cpython-3.11:$PATH"
in your .bashrc
in order to get the results you want.
Note that while changing $PATH
should be sufficient to make the shell invalidate cached command paths, you may need to start a whole new bash shell for it to actually pick up on the change. You can use type -a python3.11
to get a list of all locations which your shell currently considers candidates for executing as a bare python3.11
, ordered by preference.
3 comment threads