If you're using bash (on a Mac or GNU/Linux distro), add this to your ~/.bashrc
export PYTHONPATH="${PYTHONPATH}:/my/other/path"
Answer from awesomo on Stack OverflowIf you're using bash (on a Mac or GNU/Linux distro), add this to your ~/.bashrc
export PYTHONPATH="${PYTHONPATH}:/my/other/path"
You need to add your new directory to the environment variable PYTHONPATH, separated by a colon from previous contents thereof. In any form of Unix, you can do that in a startup script appropriate to whatever shell you're using (.profile or whatever, depending on your favorite shell) with a command which, again, depends on the shell in question; in Windows, you can do it through the system GUI for the purpose.
superuser.com may be a better place to ask further, i.e. for more details if you need specifics about how to enrich an environment variable in your chosen platform and shell, since it's not really a programming question per se.
ubuntu - How to set up Python path? - Unix & Linux Stack Exchange
Add Python to path in Ubuntu
Adding python scripts to $PATH variable without having to use “Python3 script.py”
python - PYTHONPATH on Linux - Stack Overflow
Videos
In addition to NeoTheThird's answer:
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.
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
execute the command:
echo $PATHroot1@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/binRemove your anaconda3 from your path variable that is
/home/root1/anaconda3/bin:Again set PATH variable with remaining information like below
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/binExecute python command and should redirect to your python interpreter
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. >>>
Hey guys, I'm using Ubuntu and I just downloaded the latest python version. How do I add it to path. I checked the version and it shows 3.7
So, I started writing a few python scripts to do odd jobs such as encoding/decoding base64 strings, identifying hashes etc. I put these scripts in my /home/scripts directory.
My question is, I want these scripts to be able to run in the terminal as commands without having to use something like “Python3 script.py ... “.
I have tried adding them to the $PATH variable and altering the .bashrc and .profile file, however I still have to run them through the python file.
Short of writing a bash script to middle man the commands, is there any easy ways to do this?
If this isn’t the correct sub, just let me know and I will change the post.
Thanks!
PYTHONPATHis an environment variable which you can set to add additional directories where python will look for modules and packages. e.g.:# make python look in the foo subdirectory of your home directory for # modules and packages export PYTHONPATH=${PYTHONPATH}:${HOME}/fooHere I use the
shsyntax. For other shells (e.g.csh,tcsh), the syntax would be slightly different. To make it permanent, set the variable in your shell's init file (usually ~/.bashrc).Ubuntu comes with python already installed. There may be reasons for installing other (independent) python versions, but I've found that to be rarely necessary.
The folder where your modules live is dependent on
PYTHONPATHand where the directories were set up when python was installed. For the most part, the installed stuff you shouldn't care about where it lives -- Python knows where it is and it can find the modules. Sort of like issuing the commandls-- where doeslslive?/usr/bin?/bin? 99% of the time, you don't need to care -- Just uselsand be happy that it lives somewhere on yourPATHso the shell can find it.I'm not sure I understand the question. 3rd party modules usually come with install instructions. If you follow the instructions, python should be able to find the module and you shouldn't have to care about where it got installed.
Configure
PYTHONPATHto include the directory where your module resides and python will be able to find your module.
PYTHONPATHis an environment variable- Yes (see https://unix.stackexchange.com/questions/24802/on-which-unix-distributions-is-python-installed-as-part-of-the-default-install)
/usr/lib/python2.7on Ubuntu- you shouldn't install packages manually. Instead, use pip. When a package isn't in pip, it usually has a setuptools setup script which will install the package into the proper location (see point 3).
- if you use pip or setuptools, then you don't need to set
PYTHONPATHexplicitly
If you look at the instructions for pyopengl, you'll see that they are consistent with points 4 and 5.
So the answer I've been getting is add python to environment variables which I have done
But I still get the error when running from user/downloads
python -c "from pdf2docx import Converter"
The system cannot execute the specified program.
p.s why are we banning images makes things so much more complicated?