ImportError in Python - python

I tried to execute a program using geonames_rdf, but I cant execute it by this error:
Traceback (most recent call last):
File "geo1.py", line 13, in <module>
import geonames.config.log
ImportError: No module named config.log
I read several posts abot ImportError and I check the path of the system and it is correct. I'm working in a VirtualBox with a fresh Ubuntu 16.04.
The imports of my program are:
import sys
import os
import os.path
import logging
import geonames.config.log
import geonames.compat
import geonames.adapters.search
I've also tried add this line:
sys.path.append('/usr/local/lib/python2.7/dist-packages/geonames/')
The command that I used to instal this package was
sudo pip install geonames_rdf

Try appending site-packages not dist-packages. A bit of searching it looks like dist-packages is debian specific.
sys.path.append('/usr/local/lib/python2.7/site-packages/geonames/')
Reason:
Since you're installing 3rd party python package via pip it will not go into dist-packages and python rightfully cannot find it on the path.
Reference link:
What's the difference between dist-packages and site-packages?

I just tried to use geonames_rdf, but I didn't know I needed it to do a geonames search so I installed geonames first, then discovered I had to install fiona and gdal (I'm on Windows, had to install these two using prebuilt whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/). Don't know why these dependencies aren't baked into geonames.
Anyway once I then installed geonames_rdf it seemed to install into the geonames folder in c:\Python27\lib\site-packages, added at least the adapters package. In c:\Python27\lib\site-packages\geonames there is a config folder with log.py in it.

Related

No Module name Crypto

I am trying to import Crypto in my python program but i got error.
i am working on windows. please help.
cmd
C:\Users\Raw.306498\Desktop>pip3 install --upgrade pycryptodome
Requirement already up-to-date: pycryptodome in c:\users\raw.306498\appdata\lo
cal\programs\python\python37\lib\site-packages (3.8.0)
C:\Users\Raw.306498\Desktop>python test.py
Traceback (most recent call last):
File "test.py", line 2, in <module>
from Crypto.Cipher import DES
ModuleNotFoundError: No module named 'Crypto'
C:\Users\Raw.306498\Desktop>
test.py
from Crypto.Util.asn1 import DerBitString
from binascii import hexlify, unhexlify
passw=b'21566572697461733131'
s = unhexlify(passw)
cred=str(s,'ascii')
solution to this problem for windows users is explained in the documentations here
and it says:
The root cause is that, in the past, you most likely have installed an unrelated but similarly named package called crypto, which happens to operate under the namespace crypto
Fix the problem with:
pip uninstall crypto
pip uninstall pycryptodome
pip install pycryptodome
more elaboration of the cause can be seen in this github issue
UPDATE:
If the solution quoted from documentation did not work you have to change the package folder name from crypto into Crypto.
to find where the package folder is located:
find out where your python executable is located by this command: where python.
Output should look like this:
C:\Users\_YourUserName_\AppData\Local\Programs\Python\Python37-32\python.exe
Now change your directory in cmd to the folder containing python:
cd C:\Users\_YourUserName_\AppData\Local\Programs\Python\Python37-32\
run these:
cd ..
cd cd Lib\site-packages
open the explorer in this directory:
explorer .
In the opened explorer, you can see a folder named: crypto rename it to Crypto. (the second one starts with a capital C)
i solved this issue
actually a similar named file is already store in python library so first i delete it then install pycrypto using pip

No module named pandas but pandas is already installed in linux

I have two python distributions(python2.7,python3.6) and in both I have installed pandas and numpy as well but cant use
These are the errors caused when i tried to import pandas
in python 2.7
File "/usr/local/lib/python2.7/dist-packages/pandas/init.py", line 19, in
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
then imported numpy
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try git clean -xdf (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: cannot import name multiarray
in python 3.6
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'pandas'
Most of these cases, the problem is that you are installing pandas in another environment. The easy solution here is using Anaconda.
Anaconda is focused on environments. First, you should choose installation of python2 or python3. Then, you can install this version of Anaconda in Linux: https://www.anaconda.com/download/#linux
For example:
64-Bit (x86) Installer (622 MB) Python3:
$ wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
Then you need, install in your system:
$ bash Anaconda3-5.2.0-Linux-x86_64.sh
Be cautious in the interactive dialog in order to install Anaconda. Remember the route of the installation.
When you have Anaconda in a folder named: anaconda 3 (for example). go to route: .../anaconda3/bin.
Now, you should execute:
$ source activate
Now you are in base environment, you can install the packages that you need (pandas and numpy are install by default). However, I recommend you create a new environment for each new proyect (see https://conda.io/docs/_downloads/conda-cheatsheet.pdf).
Imagine that you have (base) environment. In this environment try:
$ python
The first message gives you the python version. Anyway you can try:
>>> import sys
>>> sys.version
In order to know the version that you are using.

python 2.7.10 issues about import bs4

I installed bs4 successfully but when I import it, the command line told me that
Traceback (most recent call last):
Python Shell, prompt 3, line 1
File "C:\Python27\Lib\site-packages\bs4\__init__.py", line 303, in <module>
from . import _htmlparser
File "C:\Python27\Lib\site-packages\bs4\_htmlparser.py", line 36, in <module>
from bs4.builder import (
ImportError: No module named builder
I have searched google but I didn't find a solution..
Could our experts help me on this issue ?
thanks a lot !
my system info:
PC OS : windows 7 64bit
Python version: 2.7.10
You must first pip install beautifulsoup4, then try import bs4. If this doesn't work odds are you have a messed up pip configuration. In order to remedy this either reinstall pip, use easy_install or build from source.
In order to use easy_install just run easy_install beautifulsoup4. In order to build from source run download and extract this zip (unzip /path/to/beautifulsoup4.zip if you're at the terminal). Next cd into the now unzipped folder by doing cd /path/to/beautifulsoup and run python setup.py. The package will now be installed and ready to import!
I uninstalled bs4 package and re-installed it. and now it works...
It is quite weird because I tried to uninstall and re-install, but only this time, it worked...
Thanks for your kind help :)

Python: Sharing python site-packages libraries between two python installations

I have Python 2.7 installed on my C: drive. I then install Python 2.7 on a separate machine and copy the folder onto my J: drive. How can I share or point the J: installation of python to use my C: drive site-package packages?
i.e. How can I share my site-packages path between two installations of Python on the same machine?
When I try to install wxPython with pip and virtualenv I get the following:
pip install wxPython
Downloading from URLhttp://downloads.sourceforge.net/wxpython/wxPython-src-3.0.2.0.tar.bz2 (from http://wxPython.org/download.php)
Running setup.py egg_info for package wxPython
Traceback (most recent call last):
File "<string>", line 16, in <module>
IOError: [Errno 2] No such file or directory: '.virtualenvs\\engineer\\build\\wxPython\\setup.py'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
IOError: [Errno 2] No such file or directory: .virtualenvs\\engineer\\build\\wxPython\\setup.py
I find it difficult to build and compile on windows however the wxPython installer seems to work with virtualenv.
The comments below are useful however the question which I am asking is now that I have almost all of the packages in the virtualenv how can I make a reference to the packages which I do not have access to and are proprietary but can be installed by the user at a later date in their own python installation?
So far I have stumbled across the PkgResource api which maybe what I need.
The way to resolve this external dependency where the user does not have the power of including it in the virtualenv package is to use the package called pkg_resources:
Python code
# One approach is to find pythonhome by an environment variable
# Another is to use the windows registry but beware of different
# issue regarding 64 and 32 bit windows as shown in the link below:
Python _winreg woes
import pkg_resources
import os
pythonhome = os.environ["PYTHONHOME"]
pkgs = pkg_resources.find_distributions(pythonhome + "/Lib/site-packages")
for pkg in pkgs:
pkg_resources.working_set.add(pkg)
# import the modules
# Note: that this does not import the dependencies of the packages imported
# You could get the dependencies by following the guide here:
pkg_resource documentation
keeping in mind the following:
(Naive way of doing this:)
import pkg_resources
distributions, errors = pkg_resources.working_set.find_plugins(pkg_resources.Environment(("C:/Python27/Lib/site-packages",)))
for dsts in distributions:
for requirements in dsts.requires():
# load the requirements aswell
for requiredDsts in list(distributions):
if requirements.project_name == requiredDsts.project_name and requirements.version >= requiredDsts.specs[0][1]:
# the >= may not be whats required as it is specified in specs[0][0]
pkg_resources.working_set.add(requiredDsts)
To get setup with the virtualenv follow the instructions as given by the link provided by (bruno desthuilliers) https://pypi.python.org/pypi/virtualenv/12.0.5 followed by a nice tutorial for windows users windows tutorial on virtualenv (link provided by bruno desthuilliers):
Activate the current virtual environment
Download and install wxPython from the website (it will pickup the virtualenv)
Install any other dependencies via pip or easy_install
Perform the operation above with pkg_resources to include any packages which cannot be installed via pip or easy_install and that the user would have to install them manually.
Note: you can only import packages which are suitable for the python interpreter itself such as 32 bit or 64 bit

python module for libnet in Opensuse

I have tried to run an Python program in my Opensuse OS this Program used libnet and pcap.
import queue
import sys
import socket
import libnet
from libnet.constants import *
import pcap
I have installed libnet-devel but when i run the program i recieve the folowing message.
Traceback (most recent call last):
File "example.py", line 9, in <module>
import libnet
ImportError: No module named libnet
I have tried with different Python version, How can i solve this Problem?
using the system python (the one in /usr/bin/python):
make sure that python-pip is installed via yast
download pylibnet from http://sourceforge.net/projects/pylibnet/
install pylibnet with the command
sudo pip install ./pylibnet-3.0-beta-rc1.tar.gz
there does not seem to be a version of pylibnet packaged and available through yast, which is why you need to install one using pip (which is a program for installing python packages).
libnet-devel only installs the c library - the above installs the python library.
[edit: forgot the "install" in the pip command; added download instructions]

Categories

Resources