Python ImportError - Custom Module - python

I have installed a custom module (Twilio) using PIP, but when I try to import it, it will bring up:
ImportError: No module named 'twilio'
I'm running Windows 10 and Python 3.5. What am I missing? It seems to be an error with the paths. If it is, how do I set the paths?
Edit: I have my PYTHONHOME set to C:\Python33 and my PYTHONPATH set to C:Python33\Lib

First of all you need to check your package location.
pip show custom_package
Then check the system paths by
import sys
sys.path
If you dont' see your package path here, you can add it.
sys.path.append(custom_package_path)
If this doesn't work try reinstalling it. Or you can also install it with easy_install

Related

No module named 'paho.mqtt'; 'paho' is not a package

resolved
I have set up a conda environment with anaconda, with python 3.9 and paho-mqtt 1.6.1. I have also tested an Environment that worked for someone else but it doesn't work on my System. Other packages work, like numpy.
The code fails at the first row
import paho.mqtt.client as mqtt wit the error ModuleNotFoundError: No module named 'paho.mqtt'; 'paho' is not a package.
Does anyone have a solution or at least some ideas i could try?
For example if i create a new conda env with conda env --create env python=3.9, and then try to run import numpy it obviously doenst run. Then i do pip install numpy and run it again and it works. Though if i do the same with import paho.mqtt it doesn't work even after pip install paho-mqtt.
This error:
ModuleNotFoundError: No module named 'paho.mqtt'; 'paho' is not a package
may also occur if you have named the main program file you created as paho.py and try to run it as python paho.py or another file has the name paho.py in the same folder from which you run your program. Python will consider your program file as a module and try to find something in it that is naturally not in it. About where Python is looking for modules, see sys.path (citate: "...if path[0] is the empty string, which directs Python to search modules in the current directory first...").
In this case, rename your program file so that its name does not equal with the name of the imported module.

Module importing works in python console (pycharm) but not works on terminal

Hi i'm recently working on a module in python (package named pykiwoom)
I installed a module in conda 32-bit environment pip install pykiwoom and tried to import this
from pykiwoom.kiwoom import Kiwoom
This works perfectly fine when I execute this in python console in pycharm
However, when I try this in terminal error occurs
ModuleNotFoundError: No module named 'pykiwoom.kiwoom'; 'pykiwoom' is not a package
internal structure of package pykiwoom looks like this
pykiwoom
init.py
kiwoom.py
parser.py
Can somebody tell me why this error occurs?
I think where you install your package is important in your case. You can check the packages installed using pip list in terminal, and check if you find it there.
This solution provides overview of how to setup your files as packages and modules.
Nevertheless, I think if you install your package in the terminal using pip, you could possibly access it.

Use of installed libraries

A Python script starts with:
from pathlib import Path
import sqlite3
which I read as an initialization of Libraries needed to run the rest of the script. However if the following error is returned in the terminal:
ImportError: No module named pathlib
I am uncertain how to interpret this. One assumption is that the pathlib library is uninstalled. However on the local system Python 2.7 and Python 3.4 are installed (I believe one was system pre-installed).
How can a library be asserted to exist? In case it is missing, how can it be installed?
You have to install it first
pip install pathlib
And with that your code should work.

Downloaded package ImportError

I have recently installed python 2.17.14 to use a package which I installed in the command prompt with:
python -m pip install packageName
However, whenever I try to use it with a script provided by the package authors, I get Import Errors:
ImportError: cannot import X from YX
ImportError: attempted relative import with no known parent package.
I don't know what I'm doing wrong, as I am really new to Python. Does anyone have any ideas?
The package is called neurodesign and I downloaded the try out script from the official website "neuropowertools.org"
Best,
Max
In case anyone (who is also new to python^^) fails ridiculously at this task as well: I had to manually install all the modules used within this package for it to work as they weren't installed automatically.

ImportError: No module named ntlk

I have used ntlk in the past but now am unable to import it in python. The error is:
*ImportError: No module named ntlk*
1) I checked it was still installed, it appears in pip list as the latest version
2) I checked it was still in the system path:
import sys
sys.path
The ntlk directory appears in the list of paths
3) I checked I was able to import other modules from the sys.path without issues.
Thanks
update your PYTHONPATH variable as per your installed python [2.x or 3.x]
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages

Categories