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
CodePudding user response:
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
orwhich 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 canconda activate NAME
, and then either pip or conda install your packages.