Whenever I try to run pip (with or without any of the options) I get something like this:
$ pip --version
/usr/local/Cellar/pyenv/1.2.16/pyenv.d/exec/pip-rehash/pip: /Library/Frameworks/Python.framework/Versions/3.7/bin/pip: /usr/local/bin/python3: bad interpreter: No such file or directory
Running which pip however, returns me /Users/jalee/.pyenv/shims/pip which is an expected behaviour.
Not sure why this is happening
python3 -c "print('working')"
print working just fine
I solved this problem by using pip instead of pip3.
"bad interpreter: No such file or directory"
seems to mean that a wrong (not bad) interpreter is being used to interpret a Python file.
In my case, it seems that I was trying to install a Python 2 program with a Python 3 installer. In your case, it looks like you are trying to use a Python 2 version of pip, which processes Python 2 files, to install a Python 3 file.
Your submission indicates that your pip (which may be intended for Python 2) is associated with a Python 3 interpreter. Perhaps you might try uninstalling pip then reinstall it making sure that you get the Python 3 version.
I am currently using miniconda 3 which provides both pip and pip3.
Related
So I downloaded a module, but when I tried to use it in a program, Python threw the error:
"ImportError: No module named markovify"
When I go to try to change my .bash_profile, it shows this:
"# Setting PATH for Python 3.5
The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH"
I've been using 2.7.10 all this time, and Terminal defaults to it. (When I type in Python, that's the version it says I'm using)
I'm trying to get pip to install modules for python 2.7.10 to a different folder.
What's weird is this: I seem to have installed pyparsing with pip and it seems to work. I tried installing markovify and it throws this error message.
What am I missing?
When I go to try to change my .bash_profile, it prints this
That suggests you're using some tool to change your profile. Did you also use that tool to install markovify? You need to be clear about your environment when you have environment questions! :-)
If you installed markovify from the command line, I'd suggest opening a new terminal and running these commands, just to make sure you're working from where you think you are:
$ python --version
Python 2.7.10
$ command -v python
/usr/bin/python
The most likely problem, it seems to me, is that you got a bit tangled up and wound up doing something other than what you intended. From a fresh start, provided you're starting with the environment you want, pip should, you know, Just Work.
I'm trying to get pip to install modules for python 2.7.10 to a different folder.
That's possible to do, but are you sure that's what you want? Usually if you're using the Python interpreter you intend to, and haven't putzed with PYTHON_PATH & friends, when you run pip, it will install to its default location, which sure enough is where Python will look for it when you say to import it.
As an experiment, you might check if markovify was somehow installed for Python 3.5. Try
$ /Library/Frameworks/Python.framework/Versions/3.5/bin/python -c 'import markovify'
(You might also want to check that the Python interpreter is in fact in that folder and has that name.)
When you're working on more than one Python version, you should work on Virtual Environments:
Virtual Env on Hitchhiker's Guide
I just started learning Python, and successfully downloaded Python 3.5. I attempted to download/upgrade PIP 8.1.2 multiple times using get-pip.py, which I ran (successfully I think) but when I attempted to execute python get-pip.py
I got the error code:
File "<stdin>", line 1
python get-pip.py
^
SyntaxError: invalid syntax
I understand that pip is included in python but the pip website requires users to upgrade pip which I don't think I can since any pip commands lead to syntax errors, and do not produce the same output that most tutorial sites show. I have tried to find different ways to fix it, but I can't figure out whats wrong aside from pip not being on the computer in the first place or corrupted. Thank you for your assistance.
You won't need to upgrade pip if you just downloaded python 3.5, go to where you have your Python3.5 file and open the folder Scripts, you will find pip.exe. Open powershell and use the cd command to move to the folder containing pip.exe. From here you can use pip install to get modules.
Open Windows Powershell
PS C:Users\you> cd C:\path\to\scripts\folder\containing\pip
PS C:\path\to\scripts\folder\containing\pip> pip install module
Not sure what you are asking. If you want to run python get-pip.py do it in a windows command prompt, not in the python interpreter. But I do not know why you would want to do that.
You already have pip; there is no need to run get-pip. Upgrading can be done by pip itself.
But the reason you are getting errors is that all these commands, including pip itself, should be run at the command line, not in the Python interpreter.
I haven't tried yet out of fear I'll mess up more than I'll fix but I don't know if I can use PYTHONPATH to fix my problem. I've installed python 2.7.10 and python 3.4.2 on my Macbookpro. Python2.7 doesn't have problems, only 3.4 does. I'm afraid if I use PYTHONPATH to fix python3, it will affect python2.
Anyway, I've run:
sudo pip install blah2
sudo pip3 install blah3
pip freeze | grep blah2
blah2=2.12345
pip3 freeze | grep blah3
blah3=3.12345
and I can see I've installed the respective modules for python2 and python3 as pip freeze has shown.
However, I keep getting errors when running scripts from cmd line for python 3.4 that say the module isn't found.
On further investigation using sys.path in my script, I can see python3 from cmd line is looking for modules at
/usr/local/lib/python3.4/site-packages
which doesn't have anything inside of it, whereas Idle for python 3.4 is looking at
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
which has tons of files in there.
I don't know why this got messed up in the first place or what I forgot to do to mess it up like this but how do I tell python 3.4 to look at the /Library location for modules?
The funny thing is both python2 and 3 were installed from tar/gzip files. I ran both using the
configure; make ;make install
command but for some reason python2 is fine but python3 isn't.
This may mean the pip3 is installing to that different path.
Take a look at pip3 script and see where it is putting the package files. In my case the first line of it looks like this:
#!/opt/local/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4
Look if this is the path to the correct python3 binary. If it's not, you have two options: change this first line of pip3 to the path of your desired python3 binary, or just forget about it, use the pip directly with python3 command:
python3 -m pip install blah3
This should use the appropriate path when installing the package.
I am running Windows and am a beginner python user trying to install a few modules to run a python script. I have Python 2.7.9 and 3.4.2 both installed to the C:\ directory. I downloaded matplotlib-1.4.3.win-amd64-py3.4.exe and the corresponding .exe for python 2.7 from the Matplotlib website, but when I run the py3.4 exe the program cannot find Python 3.4 to update (Cannot install: Python version 3.4 is required, which is not found in the registry).
Python 2.7 installer works perfectly. Is there a misset PATH variable in Windows I can modify so the .exe can function properly? In CMD 'Python --version' returns Python 3.4, so unsure how to fix the issue. I installed these months ago, and may have put them in Downloads before transferring both to C:\ for clarity, which may be the problem but am unsure how to fix it.
Also, if your answer involves pip in any way please clarify how exactly to use pip in Windows. A lot of websites say to run eg. 'pip setup.py install' in the 'terminal' but do not specify if they mean Windows CMD terminal, IDLE GUI, or Python.exe command-line interface. Thanks a lot!
Not the answer to your actual question, but some clarification on your last point:
but do not specify if they mean Windows CMD terminal, IDLE GUI, or
Python.exe command-line interface.
Yes, this requires to know some context that a beginner may not have. The command pip is always used in the CMD terminal. So open CMD, and enter
pip3 install matplotlib
Notes:
Use pip3 when installing for Python 3. Then you're certain you're not accidentally installing libraries for Python 2.
pip setup.py install does not exist. You're mixing up two mechanisms to install Python packages/libraries:
One uses pip, with aforementioned pip3 install <something>. Pip goes looking online, finds a corresponding package name in a database, retrieves the URL for that package, downloads the package and installs the package. All in one command.
python3 setup.py install (again explicitly use python3 or python2 to be sure) requires you to find the package, download it, unzip it, and then in the CMD terminal, inside the unzipped folder, run the python3 setup.py install command.
This second method is usually for the latest-greatest version of a package that is not yet in pip's database, or for packages that never were in pip's database in the first place.
Generally, as a beginner, you want to stick with pip. If you ever run into the issue with the package not being available via pip, you may still be able to use pip for downloading and installing, like for example so:
pip install https://github.com/matplotlib/matplotlib/archive/master.zip
which would install the most recent matplotlib (which won't have even a version number yet, so bugs could be around).
All of these commands happen in the CMD terminal: downloading/installing packages generally all go through the terminal.
Also, when people mention "terminal", they will mean (for Windows) something like the CMD terminal. When it has to be done inside Python, it is generally called the "Python prompt". (IDLE is yet a different beast, that I'm not familiar with. I'm guessing that it has several parts, including a text editor section and a Python prompt section.)
I recently installed python3 only to realize that mysql-python as well as many other modules were not well supported with it yet. So I changed the path in my bashrc file to point to an installation of python 2.7. The problem is that when I installed python 3 I also installed distribute and pip along with it. I removed the pip and distribute files from the python3 bin directory and installed setuptools and pip using python 2.7 however now when I use the pip command to install django and mysql-python, I get a bash error python331/bin/pip No such file or directory. It's still looking for pip in the python3 install. How can I remedy this?
Thanks
...I get a bash error python331/bin/pip No such file or directory.
It's still looking for pip in the python3 install. How can I remedy
this?
bash, by default, hashes the locations of commands to avoid searching $PATH each time, so if, when you execute...
$ type pip
...you get something like...
pip is hashed (python331/bin/pip)
...you just need to clear the hash table for bash with...
$ hash -r
...then it'll pick up the version in Python 2.7 the next time you try to run pip.
Fixed it.
Renamed the directory of where the python3 was installed, bash automatically looks for the next available python install python 2.7