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
Related
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.
SkyNet is publicly available as an open-source software at https://bitbucket.org/jlippuner/skynet. I am having problems installing this software. I am using Ubuntu, and I have downloaded all needed packages using apt. All tests pass (not at first, but after restarting), but the problems start when I try to run the example code.
As instructed at the bitbucket page, I have used CMake to try to install the package, and all files seem to be installed, and the tests work.
The first line in the code is from SkyNet import *, but this just returns No module named 'Skynet' found. I have tried to reinstall and using different versions of Python, but it doesn't seem to work. Can anyone help me?
Going through the Skynet documentation install page I found this,
For python to find the Skynet module the directory in which it exists has to be added to PYTHONPATH environment variable.
Replace install_dir with directory where the Skynet module has been installed to.
echo "export PYTHONPATH=<install_dir>/lib:\$PYTHONPATH" >> ~/.bashrc
An alternative approach would be to add the path where Skynet module exists to sys.path at the top of your script file.
Example
import sys
sys.path.append("/usr/lib/Skynet")
from Skynet import *
Here is a link to documentation on how python resolves module imports
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.
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
I'm trying to get a Python package to install to my home directory because I don't have the privileges to install it system-wide.
The package is PyProj, and I am trying to install it using python setup.py install --home=~ (with Python 2.4.3), as recommended in the Python documentation. The package compiles successfully and copies itself to what I assume are the correct directories (the directory ~/lib64/python/pyproj appears during install).
But, when I load Python up and type import pyproj, I'm told ImportError: No module named pyproj.
Any thoughts on what might be going on?
You'll need to set PYTHONPATH to tell Python where to locate your locally installed packages.
For example:
[you#home]$ export PYTHONPATH="~/lib64/python"
Or, to do this within the interpreter (or script):
import sys, os
sys.path.append(os.path.expanduser("~/lib64/python"))
For more information on how Python locates installed modules, see section on The Module search Path in docs.
~/lib64/python/pyproj is not part of your PYTHONPATH. There are two or three ways around this, depending on your needs.
The first is to directly modify the path in your module, suitable if you're only going to use it from one module. As noted in the comments, this method does not do expansion on the '~' character.
import sys
sys.path.append('/home/username/lib64/python')
import pyproj
The second way is to add ~/lib64/python/pyproj to your system's PYTHONPATH, through whatever method your system suggests. A line in .bash_profile is shown below.
export PYTHONPATH=$PYTHONPATH:~/lib64/python/pyproj
See the Python Documentation for more details.