The first thing that comes to mind is that python3 didn't automatically export its path. I think that adding
export PATH="/usr/bin/python3/bin:$PATH"
to .bash_profile or .bashrc and restarting terminal could do the trick.
Answer from darxsys on Stack Overflowubuntu - How to set up Python path? - Unix & Linux Stack Exchange
linux - How do I add Python to PATH? - Stack Overflow
Adding python scripts to $PATH variable without having to use “Python3 script.py”
Add Python to path in Ubuntu
Videos
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?
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. >>>
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!
You're absolutely right, they use different PYTHONPATHs.
You can think of Python 2.x and Python 3.x as completely different programming environments. And yes, they store their packages in different locations.
To get numpy working, you can type:
sudo apt-get install python3-numpy
If you want to find out where exactly a package is kept, you can look at the module objects __path__ attribute:
>>> import numpy
>>> numpy.__path__
['/usr/local/lib/python3.5/site-packages/numpy']
You can also install python3-pip and then run pip3 install whatever to install packages for Python 3 with Pip, for packages that aren't available in Ubuntu as python3-whatever.
In case you're confused about the difference between distutils, setuptools, easy_install, pip and the rest, use pip. That's the cool one. :)
No, they use the same PATH. However, this problem isn't with the PATH.
Python 2 and Python 3 are sufficiently different that packages have to be written separately for both of them. You cannot use a package written for one with the other.
In Ubuntu, these modules are stored in different locations and are packaged separately - python-numpy for Python 2, python3-numpy for Python 3. If you want numpy with Python 3, install python3-numpy.
$ python3 -c 'import sys; print (sys.path)'
['', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '/usr/lib/python3.4/lib-dynload', '/home/muru/.local/lib/python3.4/site-packages', '/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages']
$ python2 -c 'import sys; print (sys.path)'
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
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
- Hold Win and press Pause.
- Click Advanced System Settings.
- Click Environment Variables.
- Append
;C:\python27to thePathvariable. - Restart Command Prompt.
When setting Environmental Variables in Windows, I have gone wrong on many, many occasions. I thought I should share a few of my past mistakes here hoping that it might help someone. (These apply to all Environmental Variables, not just when setting Python Path)
Watch out for these possible mistakes:
- Kill and reopen your shell window: Once you make a change to the ENVIRONMENTAL Variables, you have to restart the window you are testing it on.
- NO SPACES when setting the Variables. Make sure that you are adding the
;C:\Python27WITHOUT any spaces. (It is common to tryC:\SomeOther; C:\Python27That space (␣) after the semicolon is not okay.) - USE A BACKWARD SLASH when spelling out your full path. You will see forward slashes when you try
echo $PATHbut only backward slashes have worked for me. - DO NOT ADD a final backslash. Only
C:\Python27NOTC:\Python27\
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.