Numpy ModuleNotFoundError on pyenv python environment with Numpy installed - python

I'm rather new to coding, so please bare with me if I'm not using the optimal terminology to ask this question. I've installed and set up python on my Mac using pyenv based on the following link:
https://opensource.com/article/19/5/python-3-default-mac
I'm currently trying to execute a program, but I receive a ModuleNotFoundError on Numpy upon execution.
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'
I've checked via terminal and ensured numpy is installed, I went through the pyenv source files and confirmed numpy is there, and tried the "python -mpip install numpy" method to no avail. I'm not sure what to do at this point, so any of your suggestions would be greatly appreciated! Thank you!

Related

Error when trying to run a Python script in Power BI

I keep getting the below error when trying to run python script in power BI.
I have tried uninstalling and re-installing all numpy , pandas but to no avail.
Please i would appreciate some assistance to get this running
DataSource.Error: ADO.NET: Python script error.
<pi>C:\Users\User\anaconda3\lib\site-packages\numpy\__init__.py:148: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "C:\Users\User\PythonScriptWrapper_6bb79068-43bc-4932-896d-bb3c9e1e2a45\PythonScriptWrapper.PY", line 2, in <module>
import os, pandas, matplotlib
File "C:\Users\User\anaconda3\lib\site-packages\pandas\__init__.py", line 16, in <module>
raise ImportError(
I have tried uninstalling and re-installing all numpy , pandas but to no avail.
Since you are using the Anaconda Python distribution you are probably pretty aware that
you have to ACTIVATE conda,
before you can run PBIDesktop.exe. This especially true if you want to include the C-libraries like the ones required for numpy.
Simple as that.

Why NumPy and pandas packages are always problematic when setting up first time Python interpreter as Anaconda provided

Below is simple Line of code to try NumPy
import numpy as np
my_list = [1, 2, 3]
print(my_list)
print(type(my_list))
my_list_arr = np.array(my_list) # Here we are converting python list to numpy array
print(my_list_arr)
print(type(my_list_arr))
My question is: when I execute above lines of code using Jupyter-Notebook , it works well without any package issues BUT Why same line of code throwing NumPy , pandas and other package dependencies related issues when execute on PyCharm as .py file
FYI,
my setup of PyCharm project as;
python interpreter --> pointed to Anaconda provided
created PyCharm virtual environment - venv
Inherit-global-site-packages – Yes
Please help me. I am fed up with installing packages using conda and tired of doing package corrections one by one as and when ERRORs comes one after another package.
Any Better Solution please !!
Below is Error by Pycharm
D:\Mytech\IDE_workspace\PycharmProjects\python_anaconda_base_venv_and_global_site_packages\venv\Scripts\python.exe D:/Mytech/IDE_workspace/PycharmProjects/python_anaconda_base_venv_and_global_site_packages/python_for_data_science/my_NumPyArrays_practice.py
C:\Users\DELL\anaconda3\lib\site-packages\numpy\__init__.py:143: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "C:\Users\DELL\anaconda3\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
from . import multiarray
File "C:\Users\DELL\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
from . import overrides
File "C:\Users\DELL\anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Mytech\IDE_workspace\PycharmProjects\python_anaconda_base_venv_and_global_site_packages\python_for_data_science\my_NumPyArrays_practice.py", line 1, in <module>
import numpy as np
File "C:\Users\DELL\anaconda3\lib\site-packages\numpy\__init__.py", line 145, in <module>
from . import core
File "C:\Users\DELL\anaconda3\lib\site-packages\numpy\core\__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "D:\Mytech\IDE_workspace\PycharmProjects\python_anaconda_base_venv_and_global_site_packages\venv\Scripts\python.exe"
* The NumPy version is: "1.20.3"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
Process finished with exit code 1
but when i am executing below code it showing. it working.
import sys
print("******************************")
print("This Code using:")
print("Python Version =", sys.version)
print("Python Interpreter =", sys.base_prefix)
print("*******************************")
print("*******************************")
This Code using:
Python Version = 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
Python Interpreter = C:\Users\DELL\anaconda3
print("*******************************")
Process finished with exit code 0
As explained in this answer, the inherit-global-site-packages inherits from your Global python install. This is the install that comes with your machine or is installed "directly" into /usr/bin or the Windows equivalent. I don't think pointing the interpreter to Anaconda will make it inherit from Anaconda, because Anaconda is not considered a global python install.
What is happening is you are inheriting from a python install that you probably did not install anything to. I can think of two solutions:
Install the packages you want in your global python install (running which python or which python3 outside of a conda env should show you where that is; after finding the command that calls the global python, pip install using that command)
Use conda environments, and just set your interpreter to different conda environments, instead of making a PyCharm env. If you are not familiar with this, you can run conda create -n NAME python=X.XX where NAME is what you want to name the environment and X.XX is the version number. From there, you can conda activate NAME, and then either pip or conda install your packages.

Python3.6: error installing Pylab

There are similar questions posted on Stackoverflow that did not seem to work for me. I am trying to install the pylab module for Python. I am using OSX. I have Python 2.7, 3.6, and 3.7 installed and have been running IDLE from 3.6. I also installed Anaconda. It looks like I have the modules and libraries I need here:
/Users/[username]/anaconda3/lib/python3.6/site-packages/matplotlib
There is also a pylab.py in that same site-packages directory.
But when I run a simple Python program with:
from pylab import plot, show
I get this error message:
Traceback (most recent call last):
File "/Users/[username]/Desktop/Python/graph.py", line 1, in <module>
from pylab import plot, show
ModuleNotFoundError: No module named 'pylab'
Not sure what I am doing wrong.

Build developer's version of scipy

I am new and trying to contribute to scipy development. I forked scipy in my github and tried to build it based on this documentation. However, while trying to import scipy in Python, I get the following error:
>>> import scipy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named scipy
I also have tried installing all the necessary pre-requirements as mentioned here. I know I can do pip install scipy, but that's not the point of building the developer version of scipy, I guess. Can someone help?
I found this issue: https://github.com/scipy/scipy/issues/5893 which suggest to add scipy in your PYTHONPATH: export PYTHONPATH="$HOME/path/to/scipy/:$PYTHONPATH"
More info on how to do this per different system from scipy documentation (FAQ section):
On Linux and OSX, you can run the command:
$ export PYTHONPATH=$PWD
and on Windows
$ set PYTHONPATH=/path/to/scipy
Another workaround is also suggested in the before-mentioned issue, which is to open the scipy build as a PyCharm project and create a virtual environment within the IDE to use for your coding!
Good luck :)

How solve import error in Python when trying to import Numpy

This is the error I get when trying to import numpy on opening python (2.7.8):
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
This is the path of my python binary /usr/local/bin/python
This is the path of pip /usr/local/bin/pip
Also, when I put in pip freeze I found the numpy package numpy==1.8.0rc1
I have looked at other relevant questions, but I'm not able to diagnose the cause. I'm guessing it might be some problem in PATHS. Where do I start?
As Akshat pointed out in the comments above, I had multiple versions of Python installed. This could have been the effect of using homebrew and/or macports in the past. I followed the steps detailed in Too many pythons on my Mac OS X Mountain Lion
and did a fresh install of Python 2.7.12 I was then able to reinstall pip and the packages subsequently.

Categories