Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Adding Python 3.11 to `$PATH`

+5
−0

I built Python 3.11 from source (from GitHub python/cpython branch "3.11").

Here is what I did (after downloading the repo as ZIP)

cd Downloads
7z x cpython-3.11.zip
cd cpython-3.11
chmod +x configure
./configure
make

Everything is okay, but I can run Python 3.11 only in the cpython-3.11 directory because it is not added to $PATH. And here is the problem.

What I tried :

  1. Rename the file ~/cpython-3.11/python to ~/cpython-3.11/python3.11
  2. Open the .bashrc file located in /home/[username]/
  3. 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, cf. 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.
History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

4 comment threads

Not a good idea to manually manage Python in PATH (1 comment)
The line `export PATH="/home/hg/cpython-3.11/python3.11:$PATH` seems to be missing the closing `"`. D... (1 comment)
Do you want to replace your previous python with 3.11 or do you want to install it in addition to the... (1 comment)
It might be helpful if you would also mention your operating system. And this might be a stupid quest... (1 comment)

2 answers

+8
−0

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.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

Note that this sort of thing normally goes into the `profile` family of files that are read by login ... (1 comment)
+4
−0

The usual way is to specify an installation location with

./configure --prefix="$HOME/python"

... and then make install after make.

If you don't specify a --prefix argument to configure, it typically defaults to /usr/local (so make install will install python as /usr/local/bin/python which should already be on your PATH, and libraries somewhere like /usr/local/lib/python/3.11).

History
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »