Python: ModuleNotFound Error - python

I downloaded multiple modules (Discord API, cx_Freeze) (pip download, Windows 10) and now I wanted to use them.
But when I want to import them, it says there isn’t any module.
From my former Python using (before resetting computer) I‘ve added a pycache folder and it worked for one module. I‘m not able to reproduce it for other modules. What to do?
I‘ve only one Python version (3.6.5) on PC.
I‘ve checked the \site-packages folder and they‘re there.

If you are using python3 then try downloading the library using
pip3 install libname
but if you are using python2 then install the library using
pip2 install libname or just pip install libname
try with these command and reply

try installing your library using the command prompt in normal user and with the admin user so that you will get to know that what is happening and also if it is still not working then try installing the library into the same folder of your project using pip custom install command
pip install -t <direct directory> <package>
then use the import statement
For Example I used
pip2 install -t c:\Users\Nav\Desktop\projectss cx_freeze
then i imported the library using
#from cx_Freeze import setup, Executable
import cx_Freeze
from cx_Freeze import *
it worked.
Previously i was getting error like :
File "C:\Python27\lib\site-packages\cx_Freeze\__init__.py", line 10, in <module>
from cx_Freeze.finder import *
ImportError: No module named finder
After custom install it is working

Related

Error ModuleNotFoundError: No module named 'pdf2docx'

I am having an issue to work with the lib pdf2docx.
Here is the code I am trying to work
from pdf2docx import Converter
pdf_file = 'test_file.pdf'
docx_file = 'test_file.docx'
# convert pdf to docx
cv = Converter(pdf_file)
cv.convert(docx_file, start=0, end=None)
cv.close()
I have installed the lib using pip install pdf2docx and I have tried as well to use sudo.
I tried to use as venv like:
create a folder
inside this folder, open your command line(cmd)
pip install virtualenv
virtualenv venv
pip install pdf2docx
Any idea about how I can make the script working?
Require Python >= 3.6. pdf2docx can be installed through:
python3 -m pip install pdf2docx
I just solved the issue, it looks like I am unable to run the script using Vstudio. The script works using the command line like python3 pdf_to_docx.py.

ModuleNotFoundError: No module named 'ruamel'

I'm using a Kubernetes inventory builder script found here: https://github.com/kubernetes-sigs/kubespray/blob/master/contrib/inventory_builder/inventory.py
On line 36, the ruamel YML library is imported using the code from ruamel.yaml import YAML. This library can be found here: https://pypi.org/project/ruamel.yaml/
On my OSX device (Mojave 10.14.3), if I run pip list, I can clearly see the most up to date version of ruamel.yaml:
If I run pip show ruamel.yaml, I get the following output:
I'm running the script with this command: CONFIG_FILE=inventory/mycluster/hosts.ini python3 contrib/inventory_builder/inventory.py 10.0.0.1 10.0.0.2 10.0.0.4 10.0.0.5
Bizarrely, it returns the following error:
Traceback (most recent call last):
File "contrib/inventory_builder/inventory.py", line 36, in <module>
from ruamel.yaml import YAML
ModuleNotFoundError: No module named 'ruamel'
I have very little experience with Python, so don't understand how this could be failing. Have I installed the library incorrectly or something? From the documentation on the ruamel.yml project page, it looks like the script is calling the library as it should be.
Thanks in advance
In my case, I was installing this with pip3 install ruamel.yaml, and it was puting the package in /usr/local/lib/python3.9/site-packages/, but the python3 binary on the machine was pinned to Python 3.7, so trying to import that module was sending the ModuleNotFoundError message.
What helped to fix this, was to install the module with python3 -m pip install ruamel.yaml, running pip via the python3 binary makes sure it runs on the same version, in this case 3.7, and gets installed via the correct version number site-packages.
pip is set to point to the Python 2 installation. To install the library under Python 3, do pip3 install ruamel.yml.
you're using python 3 and want to use the package that is with python 2. Go to the directory where your python 3 is, navigate to Scripts and use the pip in there to install the needed library.
This helped me (adding version number to python):
CONFIG_FILE=inventory/mycluster/hosts.yaml python3.6 contrib/inventory_builder/inventory.py ${IPS[#]}
[python 3.10.x].
There is no package called ruamel.yaml
what worked is pip install ruamel-yaml

pyinstaller No module named grpc

My goal is to build an executable using pyinstaller. The python script I am trying to build imports grpc. The following is an example that illustrates the problem called hello.py.
import grpc
if __name__ == '__main__':
print "hello world"
I do pyinstaller hello.py and that produces the expected dist directory. Then I run it like ./dist/hello/hello and I get error ImportError: No module named grpc.
So then I installed grpc using pip install grpc. When I rebuild the artifact I now get error Import grpc:No module named gevent.socket.
Reading online indicated that the correct items to install were actually grpcio and grpcio-tools. So I tried pip uninstall grpc pip install grpcio and pip install grpcio-tools. Doing this and rebuilding the artifact gave me error ImportError: No module named pkg_resources. Trying to pip install pkg_resources gives error: Could not find a version that satisfies the requirement pkg_resources
Having all grpcio grpcio-tools and grpc install gives the same error: Import grpc:No module named gevent.socket
This seems like it should be a very simple task. I simply want to use pyinstaller to build an artifact that has a dependency on grpc, how do I do this?
I faced the same issue. I referred this document: gRPC
As per the documentation, first upgrade your pip to version 9 or higher.
Then use the following commands:
$ python -m pip install grpcio
$ python -m pip install grpcio-tools
It worked for me!
I am working on doing a PyInstaller/cx_freeze distributable of a python app using grpc.
Can you try adding --hidden-import=pkg_resources and see what happens?
This solved it for me

Error while importing requests and pyvmomi module in python

I tried to import requests in my python scripts but it shows error
>>>import requests
ImportError: No module named requests
So I tried to install it using easy_install
Path\easy_install.exe requests
in Windows, but it shows no response and when I run import again, it shows the same error.
Make sure you have requests and pyvmomi directories located under c:\pythonXXX\Lib\site-packages.
In case of absence, try to install those packages via pip on windows(here you have the instructions to install pip on windows).
Once you have done installation of pip, open the CMD prompt with administrative privilege and use the following commands to install the required python packages :
pip install requests pyvmomi
Now you could see that the packages are successfully installed.
After this, open the "System Properties" window and select "Advanced" tab and click the button "Environment variables" to set required path variables as shown below :
PYTHONHOME - "c:\Python278"
PYTHONPATH - "c:\Python278\Lib"
Edit the system variable Path and append the following :
%PYTHONHOME%;%PYTHONPATH%;
Finally open idle or python shell and import the packages as follows :
import requests
import pyVmomi
Now you are able to import with out any problem. Whenever you import packages, also check the spelling and case sensitive of the name.
Open cmd.exe that run this command:
pip install requests
Another solution is to install Anaconda which is Python distribution that comes with great package manager from here: Anaconda
Anconda python comes with built in requests library (and many more useful libraries)

Trouble importing simplegui

I installed PyDev in Eclipse to run Python programs, but I’m facing trouble importing simplegui. It is showing me this error:
import simplegui
ImportError: No module named simplegui
My installed PyDev version is 2.7.1.
You can use SimpleGUICS2Pygame.
Just change
import simplegui
by
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
in your CodeSkulptor program and run it in standard Python
Did you learn Python using CodeSkulptor?
simplegui is a custom module for CodeSkulptor, meaning that it is only available in CodeSkulptor.
More information here.
I am using a Mac, when I installed simplegui off of the Python website, I had to import it as:
import simpleguitk
I also downloaded it through terminal with the command:
sudo pip install SimpleGUITk
Simple, download simplegui.zip form http://florian-berger.de/en/software/simplegui.
unzip simplegui-x.x.x.zip
cd simplegui-x.x.x
python setup.py install
Replace x.x.x with version number. You might want to run the last step with sudo rights.

Categories