I know there are a lot of similar questions to this but I have tried all the solutions I could find and none of them seem to work.
I have a python script that I run every day through task scheduler (Windows 10) that includes the lines
import pandas as pd
import numpy as np
For about 2 weeks this script ran on schedule with no problems and then stopped working (I may have updated something at this point but I can't remember). Specifically, it no longer works when run directly through the console i.e. >python C:\dir\script.py. But it still works fine if I load the script in Spyder and run it there.
The error it throws is the following:
Traceback (most recent call last):
File "script.py", line 15, in <module>
import pandas as pd
File "C:\Users\user1\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
I have C:\Users\user1\Anaconda3\ included in the system PATH environment variable. I have also reinstalled numpy multiple times. Any ideas?
When you use conda, this might come from the fact that conda has change the way it is activated in its latest version on windows. In particular, it has trouble loading DLLs when you are not in an activated conda environment.
By running your command python C:\dir\script.py from an active conda env (using conda activate for the base env for instance), you should see this issue disapear.
Related
I am trying to use NumPy in Python. I have just installed Anaconda Python 3.7, and that all seemed to go smoothly. However, I cannot import numpy(using the line import numpy). When I do, I get the following error:
C:\Users\jsmith\anaconda3\lib\site-packages\numpy\__init__.py:140: 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\jsmith\anaconda3\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
from . import overrides
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\__init__.py", line 54, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "C:\Users\jsmith\anaconda3\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was:
DLL load failed: The specified module could not be found.
I can see it in the Enviorments tab of Anaconda Navigator, and when I try to use it in Eclipse(Pydev) it shows up under forced builtins. I took a look at my PYTHONPATH, and both my enviorment in Eclipse and my base python directory (jsmith/anaconda3) are in it. I have tried importing other libraries I see under forced builtins,and those work fine, yet numpy seems to be the only one with issues. Calling pip install numpy tells me it is already installed with version 1.18.1. I looked at this stack overflow page, and ran the first command in the answer(conda create -n test numpy python=3.7 --no-default-packages) in anaconda prompt. This worked, and then I realized the test was specific to the question, and tried base instead, and got this error:
CondaValueError: The target prefix is the base prefix. Aborting.
However calling conda activate base did nothing.
As mentioned in the comments by #cel uninstalling and reinstalling numpy using pip uninstall numpy and pip install numpy made it work.
I better way is to
import os
import sys
os.path.dirname(sys.executable)
This will give you the path to your environment. Put the path into the settings for python
Open the Anaconda Prompt:
Then, you have to go to the Conda Environment that you want to use in PowerBI. Am having an environment 'temp', so I activate it first in the 'Anaconda Prompt':
(base) C:\Users\ashish>conda activate temp
Then I go to the directory having the "PowerBI" executable file in the installation folder:
(temp) C:\Users\ashish>cd "C:\Program Files\Microsoft Power BI Desktop\bin"
Then, I launch PowerBI from the Prompt:
(temp) C:\Program Files\Microsoft Power BI Desktop\bin>PBIDesktop.exe
This fixes the NumPy error you are getting. If you want any other package to use with PowerBI, install that package in the respective "Conda Environment" (in my case it is "temp").
Make sure the Python home directory (Anaconda3) has been added to the 'Power BI Desktop' global options in the Python scripting section too.
I am running Python 3.7 on an Anaconda distribution with Windows 10.
I have a script that runs without error in a Spyder ipython console. However, I need to run it from a .bat file.
I've replicated the error with the following Python code (just an import):
import pandas
And the following .bat:
C:\Users\user\Anaconda3\python "L:\path\baterrorimporttest.py"
I get the following error:
Traceback (most recent call last):
File "L:\path\baterrorimporttest.py", line 1, in <module>
import pandas
File "C:\Users\user\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
I have no issues running this script, importing pandas, using numpy, etc. in my Spyder console.
Any tips?
to me worked with this piece of code:
call "C:\Anaconda\Scripts\activate.bat" "C:\Anaconda"
"C:\Anaconda\python.exe" "C:\Users\...\ml001.py"
pause
As per #Karl Knechtel:
Launch C:\Users\user\Anaconda3\python from the command line. You can then import pandas from the resulting interpreter prompt.
Edit your system path environment to include paths that look something like this:
C:\Users\name\Python.exe Folder\
C:\Users\name\Python.exe Folder\Library
C:\Users\name\Python.exe Folder\Library\bins
C:\Users\name\Python.exe Folder\Scripts
Not exactly sure about the mechanics behind this, but i had a similar problem and this helped. I apologize for not remembering the link that helped me resolve this issue.
I'm a new user, and would appreciate if you mark this as closed (if it resolves your question).
When I use Anaconda, importing numpy gives me the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File"C:\Users\s140041\Anaconda3\envs\testenv\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File"C:\Users\s140041\Anaconda3\envs\testenv\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\s140041\Anaconda3\envs\testenv\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File"C:\Users\s140041\Anaconda3\envs\testenv\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File"C:\Users\s140041\Anaconda3\envs\testenv\lib\site-packages\numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: The specified module could not be found.
I have already done a LOT of troubleshooting:
I do not think the issue is path-related, Since Anaconda is my only installation of python on this machine, and the problem persists after a fresh installation of windows. I have not added anaconda to Path right now, since I just use the Anaconda prompt for all my conda related commands.
I do not think it is a problem with the environments, Problem exists on base/root environment of conda as well as on a new conda environment.
Problem is not system-related, was able to reproduce it on 2 seperate systems with specified version.
Problem is not PyCharm related, running python.exe from the root folder also gives the same error.
Uninstalling / reinstalling through conda doesn't work.
Conda does seem to look in the right library for the packages, checked this through print(sys.path) in python.exe, it returns the local library of anaconda where all it's default packages are installed.
Only when I uninstall using conda and re-install using pip everything works fine... Am i doing something wrong here, or is conda broken in this installation of Anaconda?
I just switched from a normal python/venv/pip to Anaconda/conda/environments, but I must say this is not really a warm welcome... Even though I heard that the conda packagement system is better than pip/venv.
UPDATE:
I filed a bug report on github, which can be found here.
https://github.com/conda/conda/issues/7833
Very clear discussion of what went wrong can be found in the bug-report on GitHub:
https://github.com/conda/conda/issues/7833
Summarized, using PyCharm with an unactivated environment is unsupported. So either use anaconda prompt, activate your environment and launch PyCharm from there, or re-install anaconda/mini-conda with the option "add-to-path" checked
Python was working file in my machine until yesterday night.
When I run my spyder I get,
An error occurred while starting the kernel
Error in sitecustomize; set PYTHONVERBOSE for traceback:
ImportError: DLL load failed: Access is denied.
If I try to install any module or import I get the below error,
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py", line
22, in <module>
from pandas.compat.numpy import *
File "C:\ProgramData\Anaconda3\lib\site-
packages\pandas\compat\__init__.py", line 36, in <module>
from unicodedata import east_asian_width
ImportError: DLL load failed: Access is denied.
I found this is happening because of _socket.py , I tried changing _socket.pyd from another working machine but still, I could not fix this issue.
Please help, thanks in advance!
It appears that there are some other users having similar problems with kernel restart.
See here https://github.com/spyder-ide/spyder/issues/2812
Although it is difficult to see whether the above would help - maybe you could provide a way to replicate this problem?
In above thread the solution proposed is to run
conda update setuptools
An important element is always to check if you are in the correct environment or if you always work within an environment. This normally prevents many kernel and spyder issues as well as lost dependencies
You can create a new environment and reopen spyder from within the activated environment
conda create --name newEnv python=3.5
activate newEnv (WINDOWS)
source activate newEnv (MACOS/LINUX)
then
conda install anaconda
Additionally, what has helped me in the past is to go to tools-> reset spyder to factory defaults
I'm trying to learn to use Python for scientific analyses (in particular of large NETCDF files), and have installed Anaconda on my MacBookPro OSX10.10. I'm trying to use the Spyder IDE interface, but am stalled by errors with getting the netCDF4 package to work properly.
I need to use the netCDF4 package which I installed using:
conda install netcdf4
First I couldn't get any of the Anaconda packages to import in either Spyder or Python run directly in the terminal, but tried running:
export PATH=~/anaconda/bin:$PATH
Now I get all Anaconda pre-installed packages to work in Spyder (no error when I try the import command), EXCEPT for netCDF 4 which still comes up with the following error:
import netCDF4
Traceback (most recent call last):
File "<ipython-input-7-f731da2de255>", line 1, in <module>
import netCDF4
File "/Users/eriko/anaconda/lib/python2.7/site-packages/netCDF4/__init__.py", line 6, in <module>
from ._netCDF4 import (__version__, __netcdf4libversion__, __hdf5libversion__,
ImportError: cannot import name __netcdf4libversion__
However, netCDF4 imports without any error in the terminal version of Python?
The 'Code Analysis' in Spyder flags the following error in scripts where I added the import netCDF4 command:
'netCDF4' imported but unused
E402 module level import not at top of the file
W292 no newline at the end of file
I've spent too many hour Googling without finding a solution to this, so I hope the Stackoverflow community can help.