My company provided a .pyd file to work with a new API of our internal software. I followed their instructions using Python's IDLE (and python in command prompt) and it worked without any issues. When I tried the same steps using a Jupyter Notebook, I get an error
# modname.cp38-win_amd64.pyd located in installation folder of foobar
import sys
import os
sys.path.append(r"C:\Program Files (x86)\foo\bar\bin64")
import modname
This is the point when IDLE continues and Jupyter Notebook says
----> 1 import modname
ImportError: DLL load failed while importing modname: The specified module could not be found.
I installed Jupyter notebook by using "pip install jupyterlab" and run it from a command prompt in Windows. I checked using print(sys.executable) and both IDLE and Jupyter are using the same Python installation, and I also tried running python directly in the command prompt in case python.exe (Jupyter and CMD's) and pythonw.exe (IDLE's version) differed, but it worked under command prompt.
I used print(sys.path) to check for path differences but everything in IDLE's path is also in Jupyter's. All of the previous answers point to things I have tried or assume the user is using Anaconda. I can continue without using a Jupyter Notebook but had hoped to try a new workflow.
UPDATE: More Information
I loaded the pyd in Dependencies (updated open source Dependent Walker), and all of the dlls were either in the current PATH folders or C:\Windows\System32. I added the System32 folder to the path using sys.path.append with the same result.
I also used print(os.environ) in both IDLE and Jupyter to look for any differences. IDLE had a 'Home' key (C:\Users\MyUserName) that Juptyer didn't have so I added it with the same result. Jupyter had a few others but they didn't seem relevant (terminal color, lang, etc.)
Related
I am using visual studio code on windows, and I am trying to run a python code on jupyter-notebook. I have all packages installed and they work fine when it is a normal python file. But I need it to run as a notebook. Once I run the block, I immediately get the following error:
ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_5668\1439934476.py in <module>
1 import csv
----> 2 from pandas import read_csv
3 from matplotlib import pyplot as plt
4 import numpy as np
5 import os
ModuleNotFoundError: No module named 'pandas'
I made sure that requirements are already satsified for this module, and I already tried running this line in python file with no issues. Therefore, how can I solve this issue? How can I let Jupyter notebook compiler to see where these packages actually are?
The installation of pip is related to the python path specified in the environment variable. You need to select the correct interpreter in vscode.
Python is an interpreted language, and in order to run Python code and get Python IntelliSense, you must tell VS Code which interpreter to use.
From within VS Code, select a Python 3 interpreter by opening the Command Palette (Ctrl+Shift+P), start typing the Python: Select Interpreter command to search, then select the command. You can also use the Select Python Environment option on the Status Bar if available (it may already show a selected interpreter, too):
Read docs for more details.
First you need to install pandas by running the command in your console:
pip install pandas
If you don't have pip installed on your computer then install it, otherwise you won't be able to download pandas or other modules
PS: check that when you downloaded python you chose the add to PATH option
Hoping I could help
If you have a problem running jupyter notebook file make sure
You have installed jupyter notebook from anaconda from this site
Once you installed that, open anaconda navigator and click environment tab
Install python and pandas
Jupyter Notebook works like environment different from VSCode
You can also run Jupyter Notebook file on VSCode by installing Jupyter extension in VSCode
My guess is you don't installed it yet in anaconda navigator, that's what makes it error
I uninstalled "Anaconda3 5.2.0" and reinstalled "Anaconda3 2020.07" on my Windows computer two days ago. As recommended by the installer, when I installed Anaconda3 5.2.0 last year or reinstalled Anaconda3 2020.07 two day ago, I didn't add Anaconda path to the system path environment variable. Things go well when I use python from Anaconda Prompt because the Prompt has added Anaconda directories to the path variable.
However, I find a strange different behavior between Anaconda3 5.2.0 and Anaconda3 2020.07 when used outside the Anaconda Prompt. I have a bat file containing a single line C:\Anaconda3\python xxx.py, and in xxx.py I import several python packages including numpy. When I used Anaconda 5.2.0, this bat file can be executed successfully by double-click (It's equivalent to running C:\Anaconda3\python xxx.py in an ordinary CMD, which doesn't know the Anaconda path). However, after I reinstalled Anaconda3 2020.07, I get a DLL load failed error when runing this bat file because the numpy package can't be successfully imported.
I'm sure the error is caused by the path variable and I realized that getting the DLL load failed error should be a reasonable result when running C:\Anaconda3\python xxx.py in ordinary CMD because the DLL can't be found without Anaconda directories added to the path variable in CMD.
My question is why it can be executed successfully under Anaconda 5.2.0. What's special about Anaconda 5.2.0? Why can the command find those DLL files in the ordinary CMD?
Then I checked the release notes of Anaconda. Under the Anaconda 5.2.0 part, I read the following:
Windows installer uses a trimmed down value for PATH env var, to avoid DLL hell with existing software
I guess that this may be the reason. But I can't understand the meaning of a trimmed down value for PATH env var. Does anyone know how Anaconda 5.2.0 deals with the path variable so the python interpreter can find correct DLL even outside the Anaconda Prompt in an ordinary CMD?
p.s.
The DLL load failed error is not specific to numpy package. I just take it as an example.
When importing numpy in xxx.py, the error is (last line):
Original error was: DLL load failed while importing _multiarry_umath: The specified module could not be found.
If importing sqlite3 in xxx.py, the error is (last line):
ImportError: DLL load failed while importing _sqlite3: %1 is not a valid Win32 application.
Other packages may also cause similar problem. The point is that the python interpreter used outside Anaconda Prompt (by writing the full path C:\Anaconda3\python xxx.py, or by using py xxx.py if the Python Launcher is also installed) can find correct DLL under Anaconda3 5.2.0 but can not find correct DLL under Anaconda3 2020.07, though the Anaconda directories are not added to the system path variable in both cases.
This is an example of xxx.py.
import numpy
import sqlite3
print('Hello World!')
In this context, trimming down probably means simplifying, to make it easier to find out why your PATH does not help in finding what you need.
I'm trying to run my python script that I developed/tested through IDE and it's working fine over there.
But when I try to run the same script on Command Prompt (Windows 10) which has to import any module. Note that python script and the .bat file is in the same directory.
I think this is happening environment setup so I did some search and found these posts below;
import error: 'No module named' *does* exist
No module error when running python script from command prompt
Python command line Import Error
Unable to imoprt modules on python script while running on cmd
Package doesn't work if run from cmd or from the .py file.... PYTHON
https://www.programmersought.com/article/7436148385/
Here is the error snapshot
Steps followed
Python version 3.8.3
Environment variables are set under system environment variables
in the 'code.py' also added
import sys
sys.path.append('D:\program_files\anaconda3\Lib\site-packages')
Seaborn and Scipy updated the latest versions
CMD FILE look like this
I followed older solutions like set up environment variables for python libraries and python path so for not even close to get rid of this error.
Any idea to help what I'm missing here ?
Thanks
New to python, so bear with me.
I have installed Anaconda and Jupyter Notebook successfully, and I have also set up what I think is the correct Path (at least for Anaconda). From an Anaconda prompt, python works as expected, and I can import the modules I need. However, I get a ModuleNotFoundError when I try to import certain modules in Jupyter Notebook (such as cx_Oracle). I think the issue is they are running off of two different directories.
When I run sys.executable in the Anaconda prompt, I get this directory: C:\Users\username\Documents\Anaconda\python.exe
When I run sys.executable in Jupyter Notebook, I get this directory: C:\Users\username\AppData\Local\Continuum\anaconda3\python.exe
Shouldn't these be the same? I would like Jupyter Notebook to execute on the same directory the Anaconda prompt does: C:\Users\username\Documents\Anaconda\python.exe
So my question is: how do I change the Jupyter Notebook directory so it points to the same one Anaconda is using?
Thanks all. This issue has been driving me crazy.
When i try run code into Jupyter notebook i getting Import error(attached image).
I add paths to PYTHON_PATH and add %PYTHON_PATH% in system PATH, but i still get thos error
If you are using Anaconda, you must know that it ignores PYTHONPATH!. Use the following commands:
conda develop ~/models/research/
conda develop ~/models/research/slim/
here is why you need to do it in this way. When you issue the above commands, it will create a .pth file inside your current's environment site-packages folder. Then, adds those two paths to this .pth file. Then, whenever you load your Anaconda prompt, those are on the path. This works for both Linux and Windows.