Can't import scipy in Spyder: ImportError results - python

I updated some packages this morning using conda, including scipy. The new version is 1.9.3. I can no longer import certain modules from my Spyder console:
>>> import scipy.special
Traceback (most recent call last):
File "C:\Users\igurin\AppData\Local\Temp\ipykernel_19736\2717555404.py", line 1, in <module>
import scipy.special
File "C:\Users\igurin\Anaconda3\envs\latest\lib\site-packages\scipy\special\__init__.py", line 649, in <module>
from . import _ufuncs
ImportError: DLL load failed while importing _ufuncs: The specified procedure could not be found.
It works in a "plain" IPython session (launched from the Anaconda prompt), though.
To make matters worse, I can't seem to use conda to install any version of scipy other than 1.9.3.
Version info
Spyder version: 5.3.3 (conda)
Python version: 3.10.8 64-bit
Qt version: 5.15.2
PyQt5 version: 5.15.7
Operating System: Windows 10
Attempted solutions
Tried this.
Deleted my whole environment and reinstalled from scratch.

I found an answer on GitHub for Spyder. I removed Anaconda from my Windows path, and the import works now. I'm treating this as a workaround rather than a solution, though.

Related

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.

ImportError Pyo

I'm trying to import pyo in python3.8.8 and I'm not getting any results. When I try to run the command:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in
import pyo
File "C:\Users\andre\AppData\Roaming\Python\Python38\site-packages\pyo_init_.py", line 28, in
from .lib import analysis as analysis
File "C:\Users\andre\AppData\Roaming\Python\Python38\site-packages\pyo\lib\analysis.py", line 32, in
from ._core import *
File "C:\Users\andre\AppData\Roaming\Python\Python38\site-packages\pyo\lib_core.py", line 58, in
from .._pyo import *
ImportError: DLL load failed while importing _pyo: Impossibile trovare il modulo specificato.
How can I solve this?
I assume you are on windows. What version of pyo do you have installed? I saw that it was only version 1.0.1 that python 3.8 support was introduced. Try uninstalling pyo, then make sure you install the newest version. Also, did you install with pip? If you did, try installing from their downloadable releases on github. What code did you write that caused this error? I need to see your code.
Looks like you're using pc032 (032bit) Python. Last PyO version with pc032 (on Win) support is [PyPI]: pyo 1.0.1 (from 191127). But I didn't see the Python 3.8 .whl among files (neither for a couple of older versions).
Just out of curiosity: how did you install PyO?
In order to get things going either:
Switch to pc064 (064bit) Python
Use a (pc032) Python version that prebuilt .whl exists for
I've built v1.0.4 (latest at answer time) and placed the .whls at [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyO/v1.0.4. Download and install the preferred one (check [SO]: Installing pygraphviz on Windows 10 64-bit, Python 3.6 (#CristiFati's answer) (at the end) for more details about the process)

pyfits and mayvi installed package in astroconda but not visible by spyder

I have installed astroconda. After activating astroconda by command source activate astroconda I typed spyder. Then in Spyder I imported some package import pyfits and from mayavi import mlab
I see this error:
Traceback (most recent call last): File "", line 1, in
ImportError: No module named pyfits
I checked with conda list and pyfits 3.3 is in installed package list. How tell Spyder to use this package?
Spyder it is not included by default in astroconda. So, when you load it, it uses the version in the Ananconda environment.
To solve this, you only have to install it in astroconda:
source activate astroconda
conda install spyder

Not able to import Python packages

Not able to install any packages
I've tried VLC package from https://wiki.videolan.org/python_bindings
and got a traceback.
Now I am trying pygame module and this is what i get
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import pygame
File "C:\Users\Vineeth\AppData\Local\Programs\Python\Python36-32\lib\pygame\__init__.py", line 133, in <module>
from pygame.base import *
ImportError: DLL load failed: The specified module could not be found.
Please help i am pretty new to python
There are some release binaries for Python3.x, 64bit Windows at http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
I suggest you download it from that site and install it. It works for me. If you are using Windows ,it is a good way to install some packages,like lxml matplotlib.
Also you check out this question.
Hope this helps.
I tried to execute your statements and the imports worked fine for me. I have a 64bit Windows OS. And my python version Python 3.5.2 - 64bit.
Check if you have other Python versions, if you have removed them, make sure you did that right.
Ultimately I would just suggest you to do pip install pygame. The version compatibility will be handled by pip itself.

Python Spyder 2.2.5 error installing pyodbc

When I type import pyodbc in my Spyder screen i get below error. Any suggestions? How to install package pyodbc for Spyder
>>> runfile('C:/Users/myname/Documents/Python Scripts/co2nm.py', wdir=r'C:/Users/myname/Documents/Python Scripts')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\myname\AppData\Local\Continuum\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "C:/Users/myname/Documents/Python Scripts/co2nm.py", line 7, in <module>
import pyodbc
ImportError: No module named pyodbc
I was able to use other packages though such as
import networkx as nx
import os.path as path
import datetime as dt
(Spyder dev here) Spyder is not able to install packages by itself but it can use any package installed on the same Python version it is running on.
I sincerely recommend you to use the Anaconda Python Distribution because it not only comes with Spyder and all its dependencies but you can also install pyodbc quite easily with it, by running this command on a terminal:
conda install pyodbc
As the error message states, you don't have pyodbc installed, which is required for whatever you're trying to do. I would suggest you install it, from you path I assume you're on windows. There are pretty great windows instructions for installation of pyodbc here:
http://www.sperris.com/todays_goal/2008/10/installing-pyodbc-on-windows.html
Let me know if you have any questions.

Categories