0

I searched a lot and tried many of the SQ solutions but nothing helped me here... can someone check what exactly I messed up with?

My Python3 is installed in the directory here /usr/local/Cellar/python/3.7.0/

In my .bashrc I have added

export PYTHONPATH=$PYTHONPATH:/Users/swapnil.kotwal/Library/Python/3.7/lib/python/site-packages

Also, .bash_profile have

source ~/.bashrc alias python=python3 export PATH="/usr/local/bin:/usr/local/opt/node@10/bin:$PATH"

My Below command also works fine

$ python -c "import requests; print (requests.__version__)" 2.20.0

And other things are as below

SwapnilsMacBook:FAI-PEP swapnil.kotwal$ /usr/bin/python --version
 Python 2.7.10
SwapnilsMacBook:FAI-PEP swapnil.kotwal$ which python
/usr/bin/python
SwapnilsMacBook:FAI-PEP swapnil.kotwal$ whereis python
/usr/bin/python
SwapnilsMacBook:FAI-PEP swapnil.kotwal$ python3 --version
Python 3.7.0
SwapnilsMacBook:FAI-PEP swapnil.kotwal$ which pip3
  /usr/local/bin/pip3
SwapnilsMacBook:FAI-PEP swapnil.kotwal$ vi benchmarking/run_bench.py
SwapnilsMacBook:FAI-PEP swapnil.kotwal$ benchmarking/run_bench.py -b specifications/models/caffe2/shufflenet/shufflenet.json
Traceback (most recent call last):
  File "benchmarking/run_bench.py", line 18, in <module>
    from utils.utilities import getPythonInterpreter, getString
  File "/Users/swapnil.kotwal/Swapnil/FAI-PEP/benchmarking/utils/utilities.py", line 16, in <module>
    import requests
ImportError: No module named requests
SwapnilsMacBook:FAI-PEP swapnil.kotwal$ 
SwapnilsMacBook:FAI-PEP swapnil.kotwal$ pip3 install six
Collecting six
  Using cached https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Installing collected packages: six
Successfully installed six-1.11.0
SwapnilsMacBook:FAI-PEP swapnil.kotwal$ pip3 install requests
Collecting requests
  Using cached https://files.pythonhosted.org/packages/f1/ca/10332a30cb25b627192b4ea272c351bce3ca1091e541245cccbace6051d8/requests-2.20.0-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests)
  Using cached https://files.pythonhosted.org/packages/56/9d/1d02dd80bc4cd955f98980f28c5ee2200e1209292d5f9e9cc8d030d18655/certifi-2018.10.15-py2.py3-none-any.whl
Collecting urllib3<1.25,>=1.21.1 (from requests)
  Using cached https://files.pythonhosted.org/packages/8c/4b/5cbc4cb46095f369117dcb751821e1bef9dd86a07c968d8757e9204c324c/urllib3-1.24-py2.py3-none-any.whl
Collecting idna<2.8,>=2.5 (from requests)
  Using cached https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl
Installing collected packages: chardet, certifi, urllib3, idna, requests
Successfully installed certifi-2018.10.15 chardet-3.0.4 idna-2.7 requests-2.20.0 urllib3-1.24

pip list

SwapnilsMacBook:FAI-PEP swapnil.kotwal$ pip list
Package          Version   
---------------- ----------
certifi          2018.10.15
chardet          3.0.4     
idna             2.7       
pip              18.1      
pipenv           2018.10.13
requests         2.20.0    
setuptools       40.4.3    
six              1.11.0    
urllib3          1.24      
virtualenv       16.1.0    
virtualenv-clone 0.4.0     
wheel            0.32.0    
SwapnilsMacBook:FAI-PEP swapnil.kotwal$ 

But, when I ran FAI-PEP https://github.com/facebook/FAI-PEP

using command benchmarking/run_bench.py -b specifications/models/caffe2/shufflenet/shufflenet.json

I got error as below

$ benchmarking/run_bench.py -b specifications/models/caffe2/shufflenet/shufflenet.json
Traceback (most recent call last):
  File "benchmarking/run_bench.py", line 18, in <module>
    from utils.utilities import getPythonInterpreter, getString
  File "/Users/swapnil.kotwal/Swapnil/FAI-PEP/benchmarking/utils/utilities.py", line 16, in <module>
    import requests
ImportError: No module named requests
Swapnil Kotwal
  • 5,418
  • 6
  • 48
  • 92

1 Answers1

1

Please check where requests gets installed. Then check whether python is searching for the library in this directory.

In order to see where requests is installed, you can use the following pip command

pip list

compare How do I find the location of my Python site-packages directory? . In case the Location column is empty, the library was installed to the default directory.

And to see the directories in which python is searching for libraries you can use

print(__import__('sys').path)

In case requests is installed in a directory python is not looking in, I suggest reading these question: Permanently add a directory to PYTHONPATH , Install a Python package into a different directory using pip?

Also check that your python script is not executed in a virtual environment (virtualenv) where the package is not installed/available https://docs.python-guide.org/dev/virtualenvs/.

quant
  • 2,184
  • 2
  • 19
  • 29
  • sys.path is ```['', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/swapnil.kotwal/Library/Python/3.7/lib/python/site-packages', '/usr/local/lib/python3.7/site-packages']``` – Swapnil Kotwal Nov 01 '18 at 09:19
  • Can you find a requests folder with an \_\_init\_\_.py file in it in any of these directories? If no, please try installing the requests library to one of the given locations. If yes, is it working if you cd to the directory containing the requests folder in a shell, open python and execute the command "import requests"? – quant Nov 01 '18 at 09:30
  • I ```cd /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests``` and ran ```pathon3``` and then ```import requests``` it worked... I think I need to add python3 *permanently* if yes how or best way I should go ? – Swapnil Kotwal Nov 01 '18 at 09:36
  • use import sys; sys.path.append("/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages") in your script before line 18 – quant Nov 01 '18 at 09:36
  • there could be too many files having ```request``` dependency. Can I add python3 for all scripts? I removed all python related entries from my ```.bash_profile``` files – Swapnil Kotwal Nov 01 '18 at 09:37
  • Sure the howto was already included in my answer from the very beginning https://stackoverflow.com/questions/3402168/permanently-add-a-directory-to-pythonpath you need to include the directory /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages since it is where the library is installed. However you only have /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7 in your path ... – quant Nov 01 '18 at 09:39
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/182925/discussion-between-swapnil-kotwal-and-quant). – Swapnil Kotwal Nov 01 '18 at 09:41