Click here to Skip to main content
15,888,323 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Python
  File "C:\Users\Afzal\Desktop\My Folders\Python\PythonProj\gensim\parsing\preprocessing.py", line 10, in <module>
    from gensim import utils
  File "C:\Users\Afzal\Desktop\My Folders\Python\PythonProj\gensim\utils.py", line 40, in <module>
    import scipy.sparse
  File "C:\Users\Afzal\Desktop\My Folders\Python\PythonProj\scipy\__init__.py", line 75, in <module>
    from numpy.random import rand, randn
ImportError: No module named 'numpy.random'


getting this error while folder numpy is exist in the same folder where my python file is. but random folder exist in the another folder named numpy in the numpy folder.

What I have tried:

copied internal numpy folder to outside where my python file exist but there this error is being throw,

Python
ImportError: Error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree, and relaunch
        your python interpreter from there.
>>> 
Posted
Updated 31-Dec-16 21:41pm

1 solution

You cannot import numpy from its source directory because it has extension modules written in C and these have to be built before the package is complete.

Instead of using numpy from its source directory, I recommend installing it properly. Because you use scipy, you need the package numpy+mkl. (Note the usual way of downloading+installing a package with Python's package manager 'pip' won't work on Windows with this package, you'll have to do a bit more work yourself here). There is a very handy page: Python Extension Packages for Windows - Christoph Gohlke[^], where you can download the .whl files (for Windows) for scipy and numpy+mkl. (Make sure you choose the correct platform.) .whl ('Wheel') is a file format for Python packages, that you can install using the package manager 'pip'. This might be added to your PATH already during installation but if it isn't, you can find it in the Scripts\ directory of your Python installation folder.

First you have to make sure that pip can understand the Wheel files. For that you have to install the "wheel" package:
pip install wheel
If you aren't familiar with pip: this command tells pip to download "wheel" from PyPI[^], an online repository of Python packages. However as I said before, this exact way won't work for numpy+mkl and scipy, so you have to install the Wheel files like this:
pip install your_wheel_file.whl
Do that twice: once for the numpy+mkl wheel and once for the scipy wheel.

It might happen that the above command errors and says something about the wrong platform. If that happens, first check that you downloaded the correct Wheel. If you did choose the right one but it still errors, then you have to update pip:
python -m pip install pip --upgrade
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900