First of all, I should say that I am not a python expert.
I am struggling with different versions of python installed in my OS. I am running python v2.7 but after an update via brew, I got an issue. When I run a package called ilamb, I get the following error:
/usr/local/bin/ilamb-run: bad interpreter:
/usr/local/opt/python/bin/python2.7: no such file or directory
The computer is somehow looking at local/opt folder, which I suspect was created from macports. I unfortunately deleted this folder because I was trying to standardize installations via brew and/or pip to avoid the kind of errors I am struggling with now. However, my python version is located at:
which python
/usr/bin/python
How can I point to the right location?
Try installing ilamb again using
python -m pip install ILAMB
Believe you used sudo for installation which might have caused this. Try this below:
brew install python
brew linkapps python
brew link --overwrite python
Related
I am working with some python program where I need to import mysql.connector. But I am facing ImportError: No module named connector. I already read answers on same issue and also explore google to find out and try some step to fix still it not fixed.
I am working on MacOS. and I guess by default python 2.7.18 is installed and also I installed python 3.8.9.
So I came to know that I have to install pip install mysql-connector for python 2.X but when I ran this in my terminal it is showing command not found: pip . Then I tried to install pip3 install mysql-connector. for python3 and it got successfully installed.
But Still problem not fixed. Any idea how to fix this?
It could be the case where you are running the Python file with the wrong Python installation. In VS Code we can choose the interpreter using which we want to run our Python file.
By default, the Python extension looks for and uses the first Python
interpreter it finds in the system path. To select a specific
environment, use the Python: Select Interpreter command from the
Command Palette (Ctrl+Shift+P).
Just choose Python 3.8.9 from the list of interpreters. For complete guide you can refer to the documentation:
https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment
You got two Python installed in your system. Python3 and Python2.
Pip3 is just for python3.
You must use pip2 or pip2.7 for work with python2.
Search if you got the pip2 package installed is not then install it.
I'm running macOS 11.2.2 Big Sur and I'm trying to get pip to work with the latest Python 3.9.4. This turned out to be ridiculously difficult even though I've read a number of articles on the subject. Possibly, it is the debris I accumulated in the system over the years which is causing me trouble. I need advice as to how to get things right again.
Checklist:
/usr/local/opt/python/bin/python3 --version is Python 3.9.4 installed from brew in the most usual way; it's a symlink to ../Frameworks/Python.framework/Versions/3.9/bin/python3, which is in Cellar.
Both python and python3 commands are aliased to /usr/local/opt/python/bin/python3, they give the correct version.
I used both get-pip.py and ensurepip, and both of them say everything is fine: "Successfully installed pip-21.1.1 setuptools-56.0.0"
The only thing in env that has anything to do with Python is this part of PATH: /usr/local/opt/python#3.9/Frameworks/Python.framework/Versions/3.9/bin. The lack of this one is reported as warning when you install pip.
Still, I get this:
python -m pip --version
/usr/local/opt/python#3.9/bin/python3.9: No module named pip
What am I missing? 🤯
I also found this article that instructs to use pyenv, but running it on the latest macOS is yet another problem: pyenv install 3.9.4 doesn't build for some reason.
Using pointers from #gold_cy in the comments I was able to resolve the problem by running get-pip.py with an additional parameter: --prefix=/usr/local/.
While the official pip installation guide does mention that there may be problems on the systems like macOS that manage their own Python install, it doesn't say directly what you can do about it. Which is a shame, because the phrasing in PyPA » Python Packaging User Guide » Tutorials » Installing Packages is exactly the same, only the last phrase is missing from pip's page:
Warning Be cautious if you’re using a Python install that’s managed by your
operating system or another package manager. get-pip.py does not coordinate
with those tools, and may leave your system in an inconsistent state. You can
use python get-pip.py --prefix=/usr/local/ to install in /usr/local which is
designed for locally-installed software.
I was trying to resolve the problem for python3 in MacOS. The accepted answer didn't help me.
What helped me is complete reinstall of the python3:
brew uninstall python3 # if python3 worked before
brew install python3
I went thought and installed pip and then added a bunch of libraries that I like to use and then, only after installing everything, did I realize that everything went into the 2.7.2 sit-packages directory, so the Python2.7.5 version doesn't see anything.
Now, If I type python --version in the terminal, the correct version is started. However, pip is still "tied" to the default version of Python.
How do I go about telling OSX to look at the new version of Python for everything?
Honestly, one way around this is to make sure that virtualenv works with the right version, and just use pip inside the virtualenv.
A common pattern of Python installation on the mac is to use Home Brew which is a package manager for the mac. You can then install python using:
sudo brew update
brew install python
Provided you have the XCode command line tools already installed.
After I think that the Home Brew Python will be the first in the path. If this is not the case, it might be simpler to use a virtualenv by installing the package with the pip provided by the Mac Brew install (/usr/local/Cellar/python/2.7.5/bin/pip).
After this is done you need to create a virtualenv
virtualenv ~/path/to/the/env
and to activate it
source ~/path/to/the/env/bin/activate
This will be a brand new python and your path will be configured correctly (the python and the pip will be the right ones). You can always delete it, deactivate it or source it as needed.
So, I'm using 3to2 to port my Python 3.3 code back to version 2.x. I, believe, I correctly installed 3to2 by downloading the .tar.gz, cd to the file and running python3.3 setup.py build and then python3.3 setup.py install, so I don't think that is what is causing the issue.
The issue: the issue is that after I cd to the correct file, with the code I wish to use 3to2 on, I run 3to2 filename.py, which then returns the following:
Checking Python version info...
ERROR: 3to2 requires at least Python 2.7 in the 2.x branch.
Now, I have Python 3.3 installed, which I did myself and Python 2.7, which came pre-installed on my [Mac - OSX Lion 10.7.3] computer. Any ideas why this may be? Thanks!
Even though this question is pretty old, I figured I can still help if anyone else has this same issue.
If you've installed 3to2 already, uninstall it. I used pip, so if you did too, run a pip uninstall 3to2.
If you're on OSX, do a quick python --version and make sure that your current version is 2.7.*.
To get a working version of 3to2 run 'sudo python -m pip install 3to2'.
Now, when you run 3to2, it will be referencing the correct python version.
I feel your pain I spent the last hour troubleshooting this issue on my mac, below is what I did...
Open terminal, type :
brew install python
note : brew might mention that python is already installed, or that it's installed but unlinked... either way. Then type :
brew link --overwrite python
echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile
If this doesn't work try typing brew doctor, I would have never been able to fix my problem without it's feedback..
This fixed my problem, but there might another way...
I am currently trying to run Pydev with Pymongo on an Python3.3 Interpreter.
My problem is, I am not able to get it working :-/
First of all I installed Eclipse with Pydev.
Afterwards I tried installing pip to download my Pymongo-Module.
Problem is: it always installs pip for the default 2.7 Version.
I read that you shouldn't change the default system Interpreter (running on Lubuntu 13.04 32-Bit) so I tried to install a second Python3.3 and run it in an virtual environement, but I can't find any detailed Information on how to use everything on my specific problem.
Maybe there is someone out there, that uses a similar configuration and can help me out to get everything running (in a simple way) ?
Thanks in advance,
Eric
You can install packages for a specific version of Python, all you need to do is specify the version of Python you want use from the command-line; e.g. Python2.7 or Python3.
Examples
Python3 pip your_package
Python3 easy_install your_package.