Mac - Python - import error: "No module with site name"

Tonight I try to install a package called "requests" and started messing around with the terminal, and I don’t have much intuition when it comes to this kind of thing.

Mac mini OSX Version 10.9.4

In / Library / Python, I have 4 folders: 2.3, 2.5, 2.6, and 2.7.
In / Applications I have "Python 2.7" and "Python 3.4"
I can open IDLE and dial 8 + 8, and I get 16 just fine.

Here is the error I get in the terminal:

host-210-117:~ Mario$ python ImportError: No module named site host-210-117:~ Mario$ pip ImportError: No module named site 

My goal is to run this command in the terminal:

  pip install requests 

I believe the pip is already installed. I run the file "get-pip.py" in IDLE and it says the following:

  Requirement already up-to-date: pip in /Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg Cleaning up... 

Could this be somehow related to the paths? I would appreciate some recommendations / tips / hints, thanks!

Yes, and a little more information that can help resolve this issue. Here are the first few lines of the program I'm running:

  import base64 import hmac import json import requests import time import urllib import os 

What gives me this error in IDLE (so I think it imports these first few packages without problems?):

  >>> Traceback (most recent call last): File "/Users/Mario/Desktop/pyak/pyak.py", line 4, in <module> import requests ImportError: No module named requests >>> 

***** List of system paths:

sys.path ['/ Users / Mario / Desktop / pyak', '/ Users / Mario / Documents',' /Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg ',' /Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip ',' /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 ',' /Library/Frameworks/Python.framework /Versions/2.7/lib/python2.7/plat-darwin ',' /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac ',' /Library/Frameworks/Python.framework /Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages ',' /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk ',' / Library / Frameworks /Python.framework/Versions/2.7/lib/python2.7/lib-old ',' /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload ',' / Library / Frameworks /Python.framework/Versions/2.7/lib/python2.7/site-packages', '/Library/Python/2.7/site-packages']

*** one more update:

  host-210-117:~ Mario$ which python /Library/Frameworks/Python.framework/Versions/2.7/bin/python 

*** a little more information (is this supposed to happen?)

  host-210-117:~ Mario$ which pip /usr/local/bin/pip host-210-117:~ Mario$ pip ImportError: No module named site 

*** After changing .bashrc

.bashrc: this is what the file

export PATH = "$ PATH: $ HOME / .rvm / bin" # Add RVM to PATH for scripts
alias python = / library / Python / 2.7 / python

Here is the result of the work:

  pip install requests 

host-210-117: ~ Mario $ pip installation requests
Download / unpack requests
Download requests-2.4.1-py2.py3-none-any.whl (458 KB): 458 KB downloaded
Installing Compiled Packages: Requests
Cleaning ...
An exception:
Traceback (last call was last):
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 122, basically status = self.run (parameters, arguments)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py", line 283, in work require_set.install (install_options, global_options, root = options .root_path)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 1435, in the installation require.install (install_options, global_options, * args, ** kwargs)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 671, in the installation self.move_wheel_files (self.source_dir, root = root) File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 901, in move_wheel_files pycompile = self.pycompile,
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 215, in move_wheel_files Clobber (source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 205, in os.makedirs clobber (DESTDIR)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs mkdir (name, mode)
OSError: [Errno13] Access denied: '/Library/Python/2.7/site-packages/requests'

Storing debug log for failure in /Users/Mario/Library/Logs/pip.log

+10
source share
6 answers

From what I can say, you have three versions of Python on your system.

  • The one that comes with OSX /Library/Frameworks/Python.framework/Versions/2.7/
  • Python 2.7 from python.org /Library/Python/2.7/site-packages
  • Python 3.4 from python.org

pip is installed on the Python version 2.7 that you downloaded (the one that you see in the Applications folder), unfortunately, the default Python for your shell is the one that comes with OSX, and the protocol is not installed there.

IDLE also comes with loaded Python, so it keeps telling you that the package is installed, but it doesn't work from the shell.

Since you are probably using Python, downloaded from python.org as your "main" Python (after all, using the IDLE you use), you need to configure the shell environment for this Python by default.

The easiest way is to add a variable to .bashrc that creates a python alias and points it to the right binary. To do this, add this line to the /Users/yourusername/.bashrc files with . hidden by default, so you will need to write the full name of the file on the command line to open it. Add the following line:

 alias python=/Library/Python/2.7/python 

Save the file, and then close all terminal windows and open it again. Now type pip and it should work correctly, and then you can proceed to install the queries.

In the future, refer to one version of Python. I personally ignore the nested version and use one of brew , but you can stick with Python downloaded from python.org.

+4
source

I fixed mine:

brew reinstall python

He fixed all my broken paths. I think I broke it with a broken brew package that had the wrong dependency on the python version or something like that.

+2
source

site.py is the standard module that python runs by default. It allows you to configure sys.path and run some code before running your code. He should live in a standard library and can hardly be somehow missing. However, you can disable automatic module import by passing -s switch to python.

In any case, you should somehow check why the module cannot be imported. Try viewing the sys.path list.

0
source

You are trying to install the package in '/Library/Python/2.7/site-packages/requests', but this requires root privileges. This should do the trick:

 $ sudo pip install requests 
0
source

I met the same question and error info:

 ModuleNotFoundError: No module named 'xxx' 

and finally resolved using

 brew install python3 brew link python3 sudo python3 -m pip install xxx // or 'sudo python3 -m pip install -r requirements.txt' 
0
source
 sudo easy_install pip sudo pip install requests 
-2
source

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


All Articles