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
Related
I'm having trouble to import TensorFlow in my python application, BUT only
if I'm running my application in VSCode (via the debugger) OR
if I'm running it from the Terminal WITHIN VSCode.
Everything is working fine if I'm running the application from the Terminal outside of VSCode.
I'm running VSCode on macOS Big Sur Version 11.1 (M1 chipset).
I have python 3.8.2 and TensorFlow installed in a virtual environment.
Here's the steps to reproduce the Error. From the Terminal outside of VSCode I run
source env/bin/activate to activate the virtual environment
python to launch python. Output to the terminal (as expected): Python 3.8.2 (default, Nov 4 2020, 21:23:28) [...]
import tensorflow as tf
print(tf.__version__) This prints "2.4.0-rc0" to the terminal (as expected).
Now, if I repeat the exact same steps 1 and 2 in the built in VSCode terminal, I get the exact same output in 2. However, if I run command 3 and try to import tensorflow, the following error message shows up:
Traceback (most recent call last):
File "/Volumes/SSD/Jan/Documents/Github/TradingBot/env/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Volumes/SSD/Jan/Documents/Github/TradingBot/env/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found. Did find:
/Volumes/SSD/Jan/Documents/Github/TradingBot/env/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
/Volumes/SSD/Jan/Documents/Github/TradingBot/env/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Volumes/SSD/Jan/Documents/Github/TradingBot/env/lib/python3.8/site-packages/tensorflow/__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/Volumes/SSD/Jan/Documents/Github/TradingBot/env/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 39, in <module>
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
File "/Volumes/SSD/Jan/Documents/Github/TradingBot/env/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 83, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/Volumes/SSD/Jan/Documents/Github/TradingBot/env/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: dlopen(/Volumes/SSD/Jan/Documents/Github/TradingBot/env/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found. Did find:
/Volumes/SSD/Jan/Documents/Github/TradingBot/env/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
/Volumes/SSD/Jan/Documents/Github/TradingBot/env/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
It seems like the Terminal within VSCode is not using the same site-packages as the Terminal outside of VSCode, however, running print(sys.path) gives the same result.
The same problem happens if I'm trying to run my application within VSCode whereas it is working if I'm running it from the Terminal.
Any advice is greatly appreciated.
Try Python 3.7. Many people have complained tensorflow not working on 3.8, but working on 3.7. Also, try downloading it from the google tensorflow web page.
Piggy-backing off of Jay Mody in the comments above. I would first check that the shells you use in VS code is the same as the shell you are using in the non-VS code terminal.
Try the following shell commands:
echo $SHELL
If you get the same output, then I would suggest making sure the exact same python executables are being used. Try typing this in both of the shells:
which python
In VS Code, open an integrated Terminal, after activating the environment, run
pip show tensorflow
to check if the module exists in the current environment. If not, reinstall it.
I still don't know why this problem existed in the first place but I now have it resolved by installing python 3.8 via the ARM build of mini-conda.
Here are the steps.
Download mini-conda from here https://conda-forge.org/blog/posts/2020-10-29-macos-arm64/ and install it.
After installation, create a new Conda environment conda create --name python38 python=3.8. This will install the ARM version of python 3.8
Activate the new environment conda activate python38
Create a new virtual environment for your project. python -m venv myEnv
Download and unpack the ARM version of tensorflow https://github.com/apple/tensorflow_macos/releases
Run the included script to install tensorflow. /Volumes/SSD/Jan/Downloads/tensorflow_macos/install_venv.sh --prompt and point it to your newly created virtual environment of step 4.
With these steps, tensorflow could be correctly imported.
Some more reference which pointed me to this solution:
https://github.com/apple/tensorflow_macos/issues/8
https://github.com/apple/tensorflow_macos/issues/3
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'm trying to run a Python script from the Windows shell, but when I do
python path\to\file\script.py
I get an error "DLL load failed: The specified module could not be found" and it traces back to the line where I import numpy.
C:\Users\Admin>python path\to\file\script.py
Traceback (most recent call last):
File "path\to\file\script.py", line 8, in <module>
import numpy as np
File "C:\Users\Admin\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
from . import _distributor_init
File "C:\Users\Admin\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.
The weird part is that when I run it in an editor like Spyder, numpy imports just fine. Can someone help me?
Thanks
It's fixed Anaconda path issue. Check your %PATH% if it's correctly defined.
Source: https://github.com/numpy/numpy/issues/12957
This is a common problem when installing python packages, mainly in windows.
Numpy and other packages have bindings to C++ code that require some special dependencies.
Rather than trying to get the dependencies exactly right for compiling the package, you can use a precompiled "wheel" file from one of several sources.
I use Chris Gholke's site
download the .whl file and install using
pip install directory/path/package.whl
edit: and as a note, the python environment you access from powershell or cmd is different from the anaconda environment in spyder. One of the differences between conda and pip is that conda installed precompiled packages while pip does not.
I solved my issues with Numpy DLL load issues by replacing Anaconda3 with WinPython.
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.
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