ImportError: cannot import name 'convert_from_path' - python

I am trying to convert pdf to image. So I'm doing it using the pdf2image library. But somehow I get this error
ImportError: cannot import name 'convert_from_path'
keeps showing up. When I try to run the same code in command prompt it seems to work. But in Sublime editor this error keeps showing up.

From your error message, you seem to have a file named pdf2image.py in the same directory as your main script.
File "/home/raheeb/Downloads/Telegram Desktop/New python/pdf_conversion.py" ...
from pdf2image.exceptions import convert_from_path
File "/home/raheeb/Downloads/Telegram Desktop/New python/pdf2image.py" ...
from pdf2image import convert_from_path ^^
||
||
You need to rename that, because your main script is importing from that pdf2image.py instead of the actual pdf2image module which I assume is what you have installed and should be the one you actually need.
As to why it imports that instead of the true module, you need to read the Module Search Path from the Python docs. Basically, it first searches for modules in the same directory as your script, before it searches from the installation environment.

Related

Python imports from the same folder doesn't work

I created a working folder: C:\Users\robin\bayesian-optim
Inside there are module1_test.py and work.py
I have some functions in module1_test.py that I want to use in work.py, but using import module1_test as mmm in the shell gives the following error :
ImportError: No module named 'dossier_module'
It is the first thing that I do not understand. To go further,
I tried this :
import sys
sys.path.insert(0,'C:/Users/robin/bayesian-optim')
Then it worked, but my real goal is to clone some git codes in this folder and to call them instead of my example module1_test.py. When I do so, cloning "pymoo" in C:\Users\robin\bayesian-optim, I have the same problem :
File "C:/Users/robin/bayesian-optim\pymoo\pymoo\__init__.py", line 1, in <module>
from pymoo.version import __version__
ImportError: No module named 'pymoo.version'
All the .py folders inside of the cloned repo are not foundable, and it would mean that I would have to add at the beginning of every code "import sys, sys.path.insert(0, path/to/this/folder)". Can somebody help me ?

I got an error when calling kmodes module in python

When calling the kmodes package like this:
# I have also tried
# from kmodes.kmodes import KModes
from kmodes.kprototypes import KPrototypes
ModuleNotFoundError: No module named 'kmodes'
As suggested by #648trindade, all I had to do was install the package. That's not included in Anaconda by default.
I had same issue. It turned out that I named my test file as kmodes.py, and current directory is in sys.path. so python use my test file as the library.
If you have set the system path to some folder having kmodes.py file, just rename your script as something else, everything is fine.
Or you just remove the sys.path line from the code and restart the compiler

I can't import a module in Python/Windows

I'm having problem when I trying to import a custom module I have which is very simple but I'm always getting:
Traceback (most recent call last):
File "demo_module1.py", line 12, in <module>
import mymodule
ModuleNotFoundError: No module named 'mymodule'
I have tried to set environment variables:
set PYTHONHOME=C:\Software\python-3.7.4
set PYTHONPATH=%PYTHONPATH%;C:\pyproys\test
Everything is located here: 'C:\pyproys\test'
The only way it works is if I add it directly in the code "But I don't want to do it in every single script I have so don't want to maintain it in that way".
import sys
sys.path.append('C:\pyproys\\test')
print(sys.path)
Here is the script I'm trying to run:
demo_module1.py
import mymodule
mymodule.greeting("Jonathan")
'mymodule.py' is in the same folder as 'demo_module1.py'
I'm expecting the code to run fine by just executing:
python demo_module1.py
Can someone please point me out what I'm doing wrong?
Try to find the directory /lib/site-packages in your Python folder in C drive and paste your module in that folder and then restart the system. Hope it'll solve your issue.

pyinstaller not reading my hook file and doesn't work with win32com.shell

According to the docs of pyinstaller, if you name a file hook-fully.qualified.import.name.py it will read this file whenever you do an import of the matching .py file.
However, my script looks like this:
import pythoncom
from win32com.shell import shell
from win32com import storagecon
...
And pyinstaller refuses to recognize win32com.shell with the following error: ImportError: No module named 'win32com.shell'.
So I've created hook-win32com.shell.py with the following code:
hiddenimports = [
'win32com.shell.shell',
]
pyinstaller never reads this file, however it does read hook-win32com.py so I've also tried with just adding `'win32com.shell' to the above hook file but that didn't do much.
How do I get pyinstaller to read my hook file
How do I get it to include win32com.shell? (So i get rid of "No module named" in runtime of the .exe)
This seems to be the case with: https://github.com/pyinstaller/pyinstaller/issues/1322
Apparently the new python3 graph is now used everywhere in pyinstaller, so this bug seems to apply for python2 users as well.
I suggest rewriting win32com.shell calls with ctypes.shell32, or cffi.

StringIO and String Import error on installing VIM-Latex via Pathogen

I tried to install VIM-Latex using the Pathogen plugin on my machine which is running OSX Lion 10.7.5. I copied the downloaded VIM-Latex plugin files into my ~/.vim/bundle directory.
I also edited the .vimrc according to the instructions specified here.
However, I'm getting the following errors on trying to open a tex document in MAC Vim:
File "/Users/username/.vim/bundle/vim-latex-1.8.23-20130116.788-git2ef9956/ftplugin/latex- suite/outline.py", line 12, in <module>
import StringIO
ImportError: No module named StringIO
Error detected while processing /Users/username/.vim/bundle/vim-latex-1.8.23-20130116.788-git2ef9956/ftplugin/latex-suite/main.vim:
and
File "/Users/username/.vim/bundle/vim-latex-1.8.23-20130116.788-git2ef9956/ftplugin/latex-suite/pytools.py", line 1, in <module>
import string, vim, re, os, glob
ImportError: No module named string
Also, I ran a basic python script from the terminal that imported StringIO and string, and both seem to be getting imported just fine.
I'm not sure where the problem is here. Since I'm really new both with VIM and Installing Plugins, I'm not sure how I should go about debugging this issue, and so, any help will be precious!
Thanks!
StringIO and string are not available in Python 3.x. To make this code work, you have to run it with Python 2.x, e.g. Python 2.7.

Categories

Resources