0

I will first state I have searched for this problem, and found the exact same problem here ( ImportError: No module named 'requests' ) but that hasn't helped me.

I am using macports on osx (mountain lion). I have successfully installed and run a few scripts without any issues.

from the macports page, I have installed requests via the method it detailed and as far as I can tell, it has installed successfully:

daves-mbp:~ Dave$ port search requests
arpwatch @2.1a15 (net)
    Monitor ARP & RARP requests

http_ping @29jun2005 (net, www)
    Sends HTTP requests every few seconds and times how long they take

httping @2.0 (net, www)
    Ping-like tool for http-requests

py-requests @1.2.3 (python, devel)
    Python HTTP for Humans.

py26-requests @1.2.3 (python, devel)
    Python HTTP for Humans.

py27-requests @1.2.3 (python, devel)
    Python HTTP for Humans.

py31-requests @1.2.3 (python, devel)
    Python HTTP for Humans.

py32-requests @1.2.3 (python, devel)
    Python HTTP for Humans.

py33-requests @1.2.3 (python, devel)
    Python HTTP for Humans.

webredirect @0.3 (www)
    small webserver which redirects all requests

Found 10 ports.

I have python 2.7, so I installed it via:

daves-mbp:~ Dave$ sudo port install py27-requests
Password:
--->  Computing dependencies for py27-requests
--->  Fetching archive for py27-requests
--->  Attempting to fetch py27-requests-1.2.3_0.darwin_12.noarch.tbz2 from http://jog.id.packages.macports.org/macports/packages/py27-requests
--->  Attempting to fetch py27-requests-1.2.3_0.darwin_12.noarch.tbz2.rmd160 from http://jog.id.packages.macports.org/macports/packages/py27-requests
--->  Installing py27-requests @1.2.3_0
--->  Activating py27-requests @1.2.3_0
--->  Cleaning py27-requests
--->  Updating database of binaries: 100.0%
--->  Scanning binaries for linking errors: 100.0%
--->  No broken files found.
daves-mbp:~ Dave$ 

I think that looks good. Using macports is there something else I have to do before using it? I thought the python setup.py install (in the aforementioned post) may have solved my problem, however, when I search for requests in my filesystem, the only reference is burried in a path (that macports says is a store for user installed modules. And besides, there is no setup.py within that or it's parent directory.

I have restarted my terminal window (that fixed another problem earlier), but it made no difference here.

Any help is appreciated

edit:

which python reports /opt/local/bin/python

the first lines of the python interpreter DID report: daves-mbp:~ Dave$ python Python 2.7.2 (default, Jun 20 2012, 16:23:33) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin

but now I have done something and it's responding with new errors:

daves-mbp:~ Dave$ python
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 548, in <module>
    main()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 530, in main
    known_paths = addusersitepackages(known_paths)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 266, in addusersitepackages
    user_site = getusersitepackages()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 241, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 231, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 516, in get_config_var
    return get_config_vars().get(name)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 449, in get_config_vars
    import re
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 105, in <module>
    import sre_compile
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_compile.py", line 14, in <module>
    import sre_parse
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_parse.py", line 17, in <module>
    from sre_constants import *
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_constants.py", line 18, in <module>
    from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
Community
  • 1
  • 1
Madivad
  • 2,999
  • 7
  • 33
  • 60
  • Are you using the Macports or the OS X Python installation? – Blender Jul 15 '13 at 22:47
  • Have you tried a simple `pip install requests`? – Burhan Khalid Jul 15 '13 at 22:48
  • @BurhanKhalid no I didn't, I thought `pip install` was another method of installing. Isn't the way I did it above thru macports correct? I haven't installed pip purely as I just followed the steps here: http://astrofrog.github.io/macports-python/ – Madivad Jul 15 '13 at 22:53
  • 1
    @Madivad: Are you sure that you're actually using the Macports Python installation? What does the `python` banner (the first line that gets outputted when you run `python`) say? Also, what does `which python` output? – Blender Jul 15 '13 at 23:01
  • @blender I did run: sudo port select --set python python27 sudo port select --set ipython ipython27 – Madivad Jul 15 '13 at 23:10
  • which python reports: `/opt/local/bin/python` – Madivad Jul 15 '13 at 23:10
  • I have since lost the screen that detailed the install script screen output. At the end of that, there was an instruction to run to make it default. I ran that without error (I just went thru my bash history, it was the `port select --set` above – Madivad Jul 15 '13 at 23:12

1 Answers1

0

In trying to sort this out, I have broken python, and eventually I got it going again.

I think initially I had not run one of the port select --set... commands. Once I realised this might be the case, I did so, but that produced the errors at the top. MAXREPEATS, a circular reference perhaps? No idea.

I have read here (macports didn't place python_select in /opt/local/bin) and here (How do I uninstall python from OSX Leopard so that I can use the MacPorts version?) about the --set command not working and to try sudo port select python python26 (i used python27) instead.

I checked the PATH and python didn't appear, so I updated that as well.

I got my python interpreter back and low-and-behold imports requests now works.

I think at the end of it all, there were two errors:

  1. I used --set instead of the newer command, and

  2. my path wasn't set

edit: Actually, after more debugging, I found the error was on the first line of my script, I had defined which python to use (which was the default apple one, which doesn't include the module). Once I updated the shebang line, it worked.

Community
  • 1
  • 1
Madivad
  • 2,999
  • 7
  • 33
  • 60