pip in path but command not found - linux

I'm running a fresh installed OctoPi image (0.18.0). I added pip to my PATH in .bashrc file and sourced it but when I try to run pip I'm getting -bash: pip: command not found error.
When I run /home/pi/oprint/bin/pip, pip is working properly.
My path:
pi#octopi:~ $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/pi/oprint/bin/pip:

You added the full path of the executable to the path, but you're only supposed to add the directory of the executable. Every exectuable of said directory is then directly available without the directory prefix.
In other words .. instead of /home/pi/oprint/bin/pip you should add /home/pi/oprint/bin/ to the path.

I always recommend using the Python executable to locate the pip executable for you. This way, you know the right version of pip is being used to install packages that are compliant with your Python version.
$ python -m pip install <the_package_you_want>
It is really easy to end up with mismatched versions otherwise!

Related

Invoking pip packages from the CLI?

I installed a pip package (Spyder) on Debian using pip3 install spyder=5.0.5. However, running spyder from the command line interface says that it's not found. I hacked a solution by adding an alias in my .bashrc that points to some obscure start.py file that launches Spyder.
I'm sure there must be a more orthodox way of invoking Spyder, presumably by editing the $PATH, but I'm not sure how.
As #phd said in the comments, I had to edit my $PATH to point to directory where pip3 installs its packages. Namely, I had to run export PATH="$HOME/.local/bin:$PATH" and that fixed the problem.

How to upgrade python on mac if multiple versions (including upgraded version) are already installed?

I upgraded pip using the command pip3 install --upgrade pip; then, the following was printed in the terminal window:
DEPRECATION: Python 3.5 reached the end of its life on September 13th,
2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021.
pip 21.0 will remove support for this functionality.
Searching online about the right way to upgrade python on a mac lead me to two sources (1) and (2). The second source mentions modifying the .profile and bash script; these are both things I am having trouble understanding, despite some help from similar questions on these stack exchange forums like this and that. But, using suggestions from the first source, I think I've identified a potential future problem (for which I read virtual venv may be a good fix). Specifically,
$ which python
/usr/bin/python
$ which python3
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
$ brew info python
python#3.8: stable 3.8.5 (bottled)
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python#3.8/3.8.5 (4,331 files, 66.8MB)
Poured from bottle on 2020-09-23 at 04:16:21
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/python#3.8.rb
License: Python-2.0
==> Dependencies
Build: pkg-config ✔
Required: gdbm ✔, openssl#1.1 ✔, readline ✔, sqlite ✔, xz ✔
==> Caveats
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python#3.8/libexec/bin
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.8/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
==> Analytics
install: 435,972 (30 days), 1,606,776 (90 days), 3,198,770 (365 days)
install-on-request: 158,335 (30 days), 466,841 (90 days), 519,965 (365 days)
build-error: 0 (30 days)
I think this means I have python 2, python 3.5, and python 3.8 installed on my mac. I tried upgrading my python version using the multiple versions of following command (ie, python, python3, python3.8, etc):
$ pip3 install --upgrade python
ERROR: Could not find a version that satisfies the requirement python (from versions: none)
ERROR: No matching distribution found for python
I have installed python 3.8, but I'm apparently running 3.5; how do I upgrade my version of python? And how do I "clean this mess up"? In case it's relevant, I'm running macOS High Sierra 10.13.6, and the only text-editor I like/use is Atom (please no suggestions regarding vim).
EDIT #1:
After following the steps from this post, the following was opened in TextEdit.
# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
I notice that it says Python 3.5 at the top. Do I over-write the given path PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}" with PATH=/usr/local/bin? I would like to run python 3.8; will this do what I want it to?
EDIT #2:
As suggested in the edited answer, running grep PATH $HOME/.* in the terminal outputs the following in the terminal window:
grep: /Users/username/.bash_sessions: Is a directory
grep: /Users/username/.cache: Is a directory
grep: /Users/username/.config: Is a directory
grep: /Users/username/.cups: Is a directory
grep: /Users/username/.git: Is a directory
grep: /Users/username/.idlerc: Is a directory
grep: /Users/username/.lightkurve-cache: Is a directory
grep: /Users/username/.local: Is a directory
grep: /Users/username/.matplotlib: Is a directory
grep: /Users/username/.npm: Is a directory
grep: /Users/username/.nvm: Is a directory
grep: /Users/username/.oracle_jre_usage: Is a directory
grep: /Users/username/.ssh: Is a directory
grep: /Users/username/.subversion: Is a directory
grep: /Users/username/.vnc: Is a directory
So, I search for the directory containing python 3.5. Frameworks is not listed if I ls while in /Users/username/Library/, so I search elsewhere. But this worries me because I saw PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}" (from edit #1).
$ pwd
/Users/username
$ cd .local/
$ ls
share
$ cd share
$ ls
virtualenvs
$ cd virtualenvs
$ ls
PyCodes-_a3khG54
$ cd PyCodes-_a3khG54
$ ls
bin include lib src
The directory src is empty; include contains python3.5m and lib contains python3.5.
$ cd bin
$ ls
activate f2py python
activate.csh f2py3 python-config
activate.fish f2py3.5 python3
activate_this.py pip python3.5
easy_install pip3 wheel
easy_install-3.5 pip3.5
Shouldn't there be a file here that I can edit?
The output you show from:
brew info python
tells you the answer!
If I paraphrase, it says:
If you want to run Python 3.8 and pip by typing python3 and pip3, you need to put /usr/local/bin first on your PATH. If, instead, you want to run them by typing python or pip, i.e. without a version, you need to put /usr/local/opt/python#3.8/libexec/bin first on your PATH.
It's not that straightforward to say where to change your PATH because there are many possibilities as to where it is set. Your best bet is probably to look in all "dotfiles" in your HOME directory, so:
grep PATH $HOME/.*
Then you need to open the most likely looking file, and add just after the last place it is set, something like:
export PATH=/usr/local/bin:$PATH
To actually activate it, the simplest is probably to start a new Terminal and run:
echo $PATH
If it looks correct, close the Terminal with the old PATH else you'll confuse yourself. If it looks incorrect, or causes an error, immediately close the new Terminal window and retry the edit in the original Terminal.
If you want to know what you are actually running when you type python, and pip, run:
type python
type pip
If you want to know what you are actually running when you type python3, and pip3, run:
type python3
type pip3
You can interpret the outputs of the last few type commands like this:
if they contain the word local near the start, probably /usr/local/XXX, they are likely supplied by homebrew or something you have compiled or installed yourself,
if they start with /Library or contain the word Frameworks, they are probably supplied by Apple and fairly recent,
if they start with /usr/bin but without the word local, they are probably older Apple-supplied binaries,
if it says your command is "aliased", that means you have a command like alias python="something crazy" somewhere in your "dotfiles" (see above). Personally, I would remove that as it just adds another layer of indirection and confusion... YMMV on this one.
Never delete or alter anything supplied by Apple - else future macOS upgrades may fail.
So, hopefully we have established that you need to either use python and pip, or use python3 and pip3 and that they should match, i.e. that when you install a package you are installing it in a place usable by the Python interpreter you use. So, an example of a "matching" installation looks like this:
type python3
python3 is /usr/local/bin/python3
python3 -V
Python 3.8.5
pip3 -V
pip 20.1.1 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)
type pip3
pip3 is hashed (/usr/local/bin/pip3)
Notice how both my binaries contain local in their names, so they both come from homebrew and how the Python version matches the version in the pip3 -V command so I can be sure I am installing in the correct place for my Python interpreter.
Why is it hard to say where to edit your PATH? The answer is that it depends on many things. It depends on your shell, so you might see the advice to run echo $SHELL, but that only tells you your default shell, not your current shell, which you can find with ps -o comm= $$. But your login shell could be bash and you may have execed fish in your bash profile. Or you may use iTerm2 or Terminal or xterm and you may have changed your shell in the "Preferences" for that terminal program.

Python modules installed via Homebrew not importing in .command executable

New Python programmer here! 😊 Following the answer, I tried to make an executable .py file on MacOS following these steps:
Installed Homebrew via MacOS Terminal ($ /usr/bin/ruby-e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)")
Installed Python3 from Homebrew (brew install python3)
Installed required modules (e.g. python3.7 -m pip install pyfiglet)
Then, I created a simple hello_world.py file:
#!/usr/bin/env python
python import pyfiglet
print(pyfiglet.figlet_format("Hello world!"))
input("Press any key to exit.")
Next, following these instructions,
I renamed the file from hello_world.py to hello_world.command
From terminal, I entered $ cd Desktop/python to my python projects folder
Granted permission chmod +x hello_world.command to the file.
This made the python script executable, and double-clicking it opened a terminal window. However, I get the traceback ImportError: No module named pyfiglet.
I have confirmed pyfiglet is installed and works successfully when I paste the code directly into terminal using python3.7. Anyone know why the .command executable doesn't work? I followed these steps to the letter as described in this answer. Thanks for your help!

pip not running with Python 3.5

I have installed Python 3.5 and Pip but When I am type pip or pip3 in console, i get this error
The folder you are executing pip from can no longer be found.
If I run pwd, I get
/home/zahid
Pip was installed using
sudo python /usr/local/lib/python3.5/site-packages/easy_install.py pip
and output that I got was
[sudo] password for zahid:
Searching for pip
Best match: pip 8.1.1
Adding pip 8.1.1 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip3.5 script to /usr/local/bin
Installing pip3 script to /usr/local/bin
Using /usr/local/lib/python3.5/site-packages
Processing dependencies for pip
Finished processing dependencies for pip
Can anyone tell me what is going on here
which python3 returns
/usr/bin/python3
which pip returns
/usr/local/bin/pip
which pip3 returns
/usr/local/bin/pip3
echo $PYTHONPATH returns
nothing blank
Regards
Please close this terminal and open a new terminal. You may have deleted some files inadvertently. As a result the terminal is unable to locate some links or environment variables. I faced the same issue. In a new terminal everything went fine.
I had this error on my Mac and restarting fixed this problem for me.
Does sudo pip work?
If so, check to make sure your profile isn't messed up. Check your path variable using the echo command with something like echo $PATH
You need to make sure /usr/local/bin is present in your user profile.
If not, did you install pip into 3.5 and are you accidentally running some other version of python like python 2?
Create a symbolic link using
ln -s /usr/local/bin/pip /usr/bin/pip
test it by running
pip -V

"Error: Tried to guess R's HOME but no R command in the PATH"

"Error: Tried to guess R's HOME but no R command in the PATH"
after runing [ rpy2-2.5.6]$ python setup.py install commands in my redhat server
Try to install libraries always with pip instead of messing around yourself with setup.py files.
I run into the same error under windows 8, R Version 3.3.1 and Python 2.7, 32bit. The solution is easy but for this case the normal pip install rpy2 does not work.
Instead try to use the Windows-Binaries you find them here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#rpy2. Download the suiting whl file for your configuration. Then go to your download folder in cmd and simply use:
pip install rpy2-2.7.8-cp27-none-win32.whl
Note, make sure you adapt this code to your download file.
I found out that this happens to me because I'm trying to install on a python version 2.6.5 and the setup.py script tries to use a method subprocess.check_output that is new on 2.7, hence it raises an exception that leads to the this message. It seems to be wise to use a 2.7 or later version, because the check_output method is used several times in the setup.py script.
This worked for me on my Mac using python 2.7:
In my ~/.profile (or use ~/.bashrc)
I set:
export R_HOME=/Library/Frameworks/R.framework/Versions/Current/Resources/
export PATH=$R_HOME:$PATH
sourced it (source ~/.profile) and then did the standard
pip install rpy2

Resources