Python OSX $ which provides Python / Library / Frameworks / Python.framework / Versions / 2.7 / bin / python

Hello, I'm trying to run twisted along with python, but python cannot find the twisted one .

I actually ran $ pip install twisted , but it is still unavailable.

ImportError: no module named twisted.internet.protocol

It seems like most people have $ that have python on / usr / local / bin / python

but i get /Library/Frameworks/Python.framework/Versions/2.7/bin/python

Could this be a problem? If so, how can I change the PATH env?

+2
source share
4 answers

This is just great. Python can be installed in several places on your computer. When you get a new Mac, the python directory by default may be

'usr/bin/python2.7' 

You may also have a directory

 'System/Library/Frameworks/Python.framework/Versions/2.7/bin/python' 

The first is a symbolic link of the second.

If you use HomeBrew to install python, you can get the directory in

 'usr/local/bin/python2.7' 

You may also have a directory

 'Library/Frameworks/Python.framework/Versions/2.7/bin/python' 

where exactly is my directory.

The difference between the second and fourth, you can find here Installing your infrastructure

In your question, as you said, package installation completed successfully, but installed packages are still not available. I can guess that your pip directory is not in your python directory by default and the packages are installed where the pip directory is located. (Please use 'which pip' to check this)

For example, on my computer, the default peak directory

 /Library/Frameworks/Python.framework/Versions/2.7/bin/pip 

though, I also have pip in usr / local / bin.

So, all my packages installed through 'pip install' are stored in

 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages 

I hope you resolve your doubts. Similar things happened to me, and it took me a whole night to understand.

Here is the solution: Use PYTHONPATH="/usr/local/lib/python2.7/site-packages:$PYTHONPATH" to change the python directory or change the pip directory. However, I would recommend a better way: virtualenv . This can isolate Python environments and can help you easily configure packages for each project.

+8
source

By the path provided for OS X python, I guess about your rev-or-so on your OS X (leopard?), So I cannot directly compare with my machine.

But, adding packages to a basic OS X installation is always a touching thing, one check I would recommend is permissions for any packages you add. Do ls -l /Library/Python/2.7/site-packages/ and make sure that everyone has rights r (and x rights for directories) (IE -rwxr-xr-x or drwxr-xr-x ).

I had a recent case where sudo pip did not set read permissions for users on installed packages, and I think that “No module” was a mistake that I received when I tried to use them.

Since adding packages is so touchable on OS X, there are tons of tutorials on the net to do manual python installations. The first one I compared with google is "Installing / updating Python on OS X" (use at your own risk, I personally did not follow this guide)

(... the installation system of the third part of Brew is a very common method that allows people to do automated python installations)

+2
source

It's good that in the terminal I finally found out:

open the .bash_profile located in your user root directory (just do $cd in the terminal to get there) and add where the path is the location of the twisted

 PYTHONPATH="/usr/local/lib/python2.7/site-packages:$PYTHONPATH" export PYTHONPATH 
0
source

I also got ImportError: No module named xxx , although I did pip install xxx and pip2 install xxx . pip2.7 install xxx worked for me. This installed it in the python 2.7 directory.

0
source

Source: https://habr.com/ru/post/1234179/


All Articles