Linux python install path

How to set up Python path?

I have uninstall anaconda2. but now when I run Python command in terminal it says «bash: /home/user/anaconda2/python: No such file or directory» now how can I set to Python when I have python 2.7 in «/usr/lib» .

When you installed anaconda2, did you add any PYTHONPATH directives to your startup file(s) (such as your ~/.bashrc )? You probably just need to remove these, rather than set any additional path.

4 Answers 4

I’m assuming that when you installed anaconda 2, you manually set the PYTHONPATH environment variable, by putting something like

PYTHONPATH=/home/user/anaconda2/python export PYTHONPATH 

in your .bash_profile or .bash_rc .

But since you deleted the /home/user/anacanda2/ directory, that path no longer exists.

Thus you want to change PYTHONPATH to point to the executable in /usr/lib , by changing the above to

PYTHONPATH=/usr/lib/my_python_distribution export PYTHON 
root1@master:/usr/lib/python2.7$ echo $PATH /home/root1/anaconda3/bin:/home/root1/NAI/Execution/HDE/x86_64.linux/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/root1/java/jdk1.8.0_74/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/root1/NAI/hadoop-2.7.3/bin 
export PATH=/home/root1/NAI/Execution/HDE/x86_64.linux/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/root1/java/jdk1.8.0_74/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/root1/NAI/hadoop-2.7.3/bin 
root1@master:/usr/lib/python2.7$ python Python 2.7.14 (default, Sep 18 2017, 00:00:00) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 

Источник

Add Python to Path in Linux

This article will cover four things: explain what PATH is in Linux, how to add Python to PATH, work on an example to demonstrate concepts, and lastly, for your convenience, discuss removing a directory from PATH.

Читайте также:  Python datetime день года

What is PATH in Linux

PATH is an environment variable that contains a list of paths separated by a colon on Linux and a semi-colon in Windows.

Programs use the PATH variable to locate binaries (“executables”). For example, when you start Python from the terminal, the program will search for Python binaries in predefined directories. Among places to search are paths provided in PATH.

You can view the directories in PATH by running the following command on the terminal.

Most executable binaries are located at bin/, /usr/bin, /usr/local/bin, and /local/bin. These paths are already on the PATH (as shown above). That means most programs (including Python – see Figure below) should easily be started from the terminal using the executable’s name.

Adding a path into the PATH variable in Linux

If you’re using bash, add this line to your .bashrc located in the home directory

For example, the following line adds /usr/.local/bin/python to the PATH.

Save the .bashrc file and run the following command to refresh your bash session.

Note: You can run this command to accomplish all the above:

Alternatively, you can add a path directly from the shell. Depending on the shell type, a directory can be added by running any of the following commands on the terminal:

Example

In this example, we start by installing Python 3.11 on the Desktop – on a directory that is not in PATH.

Immediately after installing this Python, I got this warning:

WARNING: The scripts pip3.10 and pip3.11 are installed in '/home/kiprono/Desktop/python311/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Python 3.11 is installed in the bin folder. We need to add that folder into PATH; then, we can simply run “python3.11” to wake up this Python. We can do that by running the following:

Removing a directory from the PATH

You can run this command on the terminal to remove a folder from PATH.

PATH = $ ( REMOVE_PART = «/path/to/remove» sh — c ‘echo «:$PATH:» | sed «s@:$REMOVE_PART:@:@g;s@^: \ ( . * \ ) :\$@\1@»‘ )

Note: You may also have to remove the path from the .bashrc file to have a directory deleted from the PATH completely.

Conclusion

PATH is an environment variable containing a list of paths searched when looking for program executables. Adding Python to PATH means adding the location to the Python binary into the environment. This is done by running the following command on the terminal export PATH=/path/to/add:$PATH.

Источник

How to Find the Python Installation Path on Ubuntu, Debian, or Linux Mint

There comes a time now and again when you might want to know where your Python installation path on your Ubuntu, Debian, or Linux Mint distros is located.

Generally, by default, your Python binary is located at /usr/bin/python but it may not always be a guarantee depending on the version you are using. As you can see from this post you can actually install a different version from the default that comes with your distro.

As with the case with many things on Linux systems, there is more than one way to reliably get the Python installation path on that system.

Getting the Python Installation Path Using PYTHONPATH

You can get the value of PYTHONPATH only if it has been set. This is an environment variable that is available on the system. If it has not been set then the result of running any one of the commands below will not return anything.

If the above commands do not work you can also get the path using the which command as shown below.

$ which python /usr/bin/python

Conclusion

Once you know the path of the default Python installation path for your system you can permanently add it as an environment variable by opening the startup file you use for your default shell. This is usually ~/.profile in Ubuntu.

Open the file in your preferred editor and add the following line at the end of that file.

export PYTHONPATH=/usr/bin/python

You then need to restart your terminal to effect the change. You can also run the above on the command-line if you just need it to last the current session.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Источник

How to add python path in Ubuntu 16.04

I’m trying to run a scrapy project on a ubuntu server. For which I need to add the project path to python path. I created a .bash_profile file in the /home directory with the following contents:

PYTHONPATH=$PYTHONPATH:/home/john/Desktop/myscraper/ EXPORT $PYTHONPATH 
ImportError: No module named myscraper.items 
  • /home/john/Desktop/myscraper/
  • /home/john/Desktop/myscraper
  • home/john/Desktop/myscraper/
  • home/john/Desktop/myscraper

Did you really create it in the /home directory — or in your $HOME directory? Did you really write EXPORT — or export ?

I wrote EXPORT all in caps, and created the file in the /home directory. I don’t know what you mean by the $HOME directory.

2 Answers 2

Ubuntu does not use ~/.bash_profile by default. You should use ~/.profile instead.

The path you should use is /home/john/Desktop/myscraper , though /home/john/Desktop/myscraper/ would also work. Paths that don’t start with slashes are relative, not absolute, so will not work unless the working directory is / . More details here on Wikipedia.

You can put the definition and export statements together, and if PYTHONPATH is not already defined, you can leave off the $PYTHONPATH: at the start.

export PYTHONPATH=/home/john/Desktop/myscraper 

Config files belong in your personal home directory ( /home/$USER , $HOME or simply ~ ), not in the /home directory. In your case that will be /home/john .

Please also make sure to use the correct casing, it’s export in all lowercase.

Since export is not accessing but referencing the variable, you do not use the $ sign: export PYTHONPATH

Are you sure you want to have this in your .bash_profile and not your .bashrc ? You can read up on the difference here.

In any case you will have to run source ~./bash_profile (or source ~./bashrc if you go with that) for your changes to take effect.

Источник

Оцените статью