This error is showing to me when I am importing PyPDF2 on VisualStudioCode code editor and trying to create a GUI using Tkinter this is my first GUI code and I am still learning. I am having error in importing PyPDF2. The code is-
import tkinter
import PyPDF2
from PIL import Image, ImageTK
root = tkinter.Tk()
It's also showing error in the PIL one and I can't configure them out:
The error:
'''App.py C:\Users____________________\Downloads 2
import "PyPDF2 could not be resolved
Pylance(reportMissingImports) [3,8]
⚠ Import could not be resolved from source
Pylance(reportMissingModuleSource) [4,6]
With reference to Diagnostic Severity Rules, reportMissingModuleSource means
Diagnostics for imports that have no corresponding source file. This
happens when a type stub is found, but the module source file was not
found, indicating that the code may fail at runtime when using this
execution environment. Type checking will be done using the type stub.
In short, there's no such module in current used python environment.
After selecting python interpreter, open a new integrated Terminal then run pip show PyPDF2. If you get detailed information and its location is current interpreter\lib\site-packages, reload window should solve your question. If not, please reinstall it.
Related
I have a simple user interface with tkinter that works perfectly fine. However, when I import another python module, whenever I use the button that calls this specific line of code (the second one):
from tkinter.filedialog import *
files = askopenfilenames()
(which works fine normally and even gets the files etc...) Jupyter notebook crashes without any error message, making it hard to understand what the problem is. After investigating, I discovered that this error happens because in the other module that I import in this interface file, there is this import:
from sklearn.cluster import KMeans
When I comment out this import in the other module and try again, the button event works fine and allows me to select files. However, when I uncomment that import line again, the same problem happen.
Since there is no error message, it is hard to understand the problem and I searched but couldn't find any known problem between KMeans and this Tkinter function. Any help would be really appreciated.
Due to the lack of error message, it was impossible to find the exact cause of the problem. Suspecting a conflict in libraries, I created a new environment and installed libraries again. If anyone faces a similar issue, I suggest using conda to install libraries instead of pip as much as possible, and only use pip when no other choice is present.
This is a bit long so bear with me.
I am trying to learn both Python and Linux and am very new to both. I am currently doing some reading on deep learning from the following:
http://neuralnetworksanddeeplearning.com/chap1.html
I am attempting to import the mnist_loader package to use the associated data for testing the script that was previously written. However, upon typing import mnist_loader into the Linux command line, I was given the following:
"the program 'import' can be found in the following packages:"
at which point it listed some packages. Because I'm new to Linux and I don't have admin privileges, I decided to go a route that I understood better; that is to create a new python script and simply use the import command within (which has worked in all previous attempts).
I created a python script and tried import mnist_loader and received the following error:
"ModuleNotFoundError: No module named 'mnist_loader'"
I then checked my C drive and found that the file was indeed there. Here is a link to the Git repository where the files may be found:
https://github.com/MichalDanielDobrzanski/DeepLearningPython35
Next I moved on to trying to directly input the path to the file as follows:
import importlib.util
mnist_loader = importlib.util.spec_from_file_location("mnist_loader",r"C:\Users\XXXXXX\Documents\neural-networks-and-deep-learning-master\neural-networks-and-deep-learning-master\src\mnist_loader.py")
training_data, validation_data, test_data = mnist_loader.load_data_wrapper()
However, this produced the following error:
"AttributeError: 'ModuleSpec' object has no attribute 'load_data_wrapper'"
Note: the last line is used to collect the necessary data from the nist files.
I am running out of thoughts at this point and would love some feedback on all my "wrongdoings" up till now.
Thanks in advance!
P.S. It is worth noting that the book uses a package designed for Python 2.X whereas I am using 3.6. The readme provided by the book file location mentioned a different location where a Python 3.6 version could be found which is what I am going with.
Been a while since I have worked with Python, but I have some ideas as to what would cause the specific errors you are seeing. First I would suggest setting a PYTHON_PATH environment variable with the path you have that contains the module you want to import, this does not require administrator privileges fortunately. As for the load_data_wrapper attribute, you might have to do a from from mnist_loader import * to import all the functions inside the mnist_loader module.
I don't understand how this happened. myscript.py works, Tkinter is installed. However once I converted it to .exe using pyinstaller, I ran myscript.exe, I got a message in command prompt saying "No module named Tkinter".
How can I fix this?
I've already tried to convert it several times, tried using --noupx, and also tried reinstalling pyinstaller. Thanks
PyInstaller - Hidden Imports
Try using the --hiddenimport flag. Do --hiddenimport=Tkinter, or replace the Tkinter with whatever module you need. The issue seems reoccurring throughout the PyInstaller community. Here is one article.
Name Space
Tkinter has changed its namespaces from Python 2 to Python 3. It's now named tkinter in Python 3 and Tkinter in Python 2. This is the code I like to use so it's cross-version.
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
Then you can reference Tkinter as tk. Or if you do from Tkinter import * you can just use everything without a namespace. See the list here for more of the name changes between version.
I'm introducing myself to PyQt5 through one of its included examples. On this windows 7 machine, I have installed Python 3.4 x64, and PyQt5 using its binary provided on riverbankcomputiong.com. The documentation says that the binary already includes everything necessary to run. I (perhaps incorrectly) assumed that i can safely skip the "configure" and "build" steps at Riverbank's installation guide, since the guide only talks about .zip, .tar, etc. files.
I used the tutorial located here:
http://www.pythonschool.net/pyqt/introduction-to-pyqt/
Which also says "just run the binary to install pyqt4 there is no step three."
When i attempt to run any tutorial containing reference to PyQt4 or PyQt5:
from PyQt5.QtCore import *
I get the following error message:
ImportError: DLL load failed: The specified module could not be found.
But when i enter the following:
import PyQt5
The interpreter seems to be okay with it -- no errors.
I can't help but think I've done something wrong installation, because even when I run the examples included with PyQt4/PyQt5, i get importerrors. It seems as though QtCore doesn't even exist in relation to PyQt4 or PyQt5. What's going on here?
There seem to be a few possibilities:
You might need to update your PATH environment variable to include the location where the library is installed (i.e. directory location where the DLLs are)
Take note of where you're launching the interpreter or scripts from as their current path may not necessarily include what you expect.
You can check this with:
>>> import os
>>> os.environ['PATH'].split(os.pathsep)
Make sure the installation process was truly successful (i.e. zero errors) and that you downloaded the correct binary package for your PC's architecture.
I ran into a similar issue with PySide where import PySide would work but import PySide.QtCore would fail.
I'd expect the code to work after verifying those things:
>>> from PyQt5.QtCore import *
>>>
If it doesn't, update the question with additional details like things you checked, their values, error messages, etc.
I have a Tkinter program that i use for time management. I decided to have it scan my inbox in outlook to check emails for tags, and then based on the tag, add it to my list of tasks to do for the night.
The code i wrote works just fine, but i'm getting an error when I import win32com.client. I can import it in IDLE, but it is having problems importing when i try to run the code with a .bat file, or double clicking the .py file.
I have found several people with similar problems, but from what i can tell, it's having problems with win32api module, or pywin32
Traceback (most recent call last):
File "my_program_filename.py", line 1, in <module>
import win32com.client
File "c:/Python27/lib/site-packages/win32com/__init__.py", line 5, in <module>
import win32api, sys, os
ImportError: DLL load failed: The specified module could not be found
I'm really confused. When i get the sys.path it's the same with IDLE as it is running from the .py file with the exception of an added "c:/users/username/desktop/timer" for my .py file.
I'm really lost and haven't had to mess with the system path, but I'm not able to figure out what i need to do to fix this.
What do I need to do to get pywin32 working so I can use win32com.client?
Any help is greatly appreciated. Thanks!
IIRC, the problem was attempting to link to the debug build. I think i had to dupe the release build and rename it to be debug or something.
try building release and see if it "just works". if so, you have a direction to explore
this is an issue of not having the correct paths in the sys.path. If you make sure that all of the pywin32 folders are in the sys.path(If you check in IDLE it can show that the folders are included even when they aren't?!?!?).
You also have to make sure you run your code from inside your Python directory or it will fail to import win32api. I also found that if you do anything in a function that uses pywin32 and you accidentally misspell the function when you call it, the whole import fails without telling you your function is misspelled. You can also navigate to the /Python27/Lib/site-packages/win32com/client folder and run makepy.py to make sure the right Object library is installed.
When you run makepy.py, you select the COM object you want to use and it creates packages specific to what you want to use. I don't fully understand why this is, but once i did this and ran my file from the Python folder it worked! There is a more in depth explanation on how to get this working right here.
I found this link to be the solution rather than the win32com/client as indicated above: win32com import error python 3.4
in my case typing in cmd:
python C:\Python27\Scripts\pywin32_postinstall.py -install
I hope this helps