python 2.7 cannot import geocoder library - python

Python 2.7.10 on win32. windows 8.1
used pip to install geocoder library https://pypi.python.org/pypi/geocoder/1.8.0
get this error when I try and import the library
>>> import geocoder
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\ArcGIS10.4\lib\site-packages\geocoder\__init__.py", line 36, in <module>
from geocoder.api import get, yahoo, bing, geonames, mapquest, google, mapbox # noqa
File "C:\Python27\ArcGIS10.4\lib\site-packages\geocoder\api.py", line 29, in <module>
from geocoder.freegeoip import FreeGeoIP
File "C:\Python27\ArcGIS10.4\lib\site-packages\geocoder\freegeoip.py", line 6, in <module>
import ratelim
File "C:\Python27\ArcGIS10.4\lib\site-packages\ratelim\__init__.py", line 6, in <module>
from decorator import decorator
ImportError: No module named decorator
>>>
I thought just an install of the decorator library would fix the situtation but that library was already installed
C:\Python27\ArcGIS10.4\Scripts>pip install decorator
Requirement already satisfied: decorator in c:\python27\arcgis10.4\lib\site-packages
update
C:\Users\rizagha>python --version
Python 2.7.10
C:\Users\rizagha>python
Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from decorator import decorator
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named decorator
something that may be complicating this is I have python 32 bit and 64 bit installed via arcgis...

Try running the following command to install the module
[root#server] python -m pip install decorator
This should install the module to the python library of the interpreter that starts when you run the python command
then try start up your interpreter again and try to import the module (assuming it doesn't say it's already satisfied)
[root#server] python
>> from decorator import decorator
>>
if it does say that it's already satisfied, then you can try to uninstall it using pip and then reinstall it by explicitly specifying the python -m command
[root#server] pip uninstall decorator
[root#server] python -m pip install decorator
then you can check to see if the module is available in your default interpretor
[root#server] python
>> from decorator import decorator
>>

Related

Can not import an already installed package module

I want to install a package called Xsequence https://github.com/fscarlier/xsequence
in Windows vie git clone command and then I used python to install it
git clone https://github.com/fscarlier/xsequence.git
cd xsequence_master
python setup.py install
I have several python versions installed, put the one that was used in the installation was in the first path.
C:\Users\musa\AppData\Local\Programs\Python\Python310\python.exe
C:\Users\musa\Anaconda3\python.exe
C:\Users\musa\AppData\Local\Microsoft\WindowsApps\python.exe
The issue is that when I import the package Xsequence it works fine,
But when I try to import any other module from inside this package it doesn't work
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xsequence
>>> from xsequence.lattice import Lattice
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\musa\AppData\Local\Programs\Python\Python310\lib\site-packages\xsequence-0.0.0-py3.10.egg\xsequence\lattice.py", line 11, in <module>
File "C:\Users\musa\AppData\Local\Programs\Python\Python310\lib\site-packages\xsequence-0.0.0-py3.10.egg\xsequence\elements.py", line 13, in <module>
ModuleNotFoundError: No module named 'xsequence.helpers'
I checked the package folder manually it contains the module Xsequence.helper.
The strange thing that all the module can be imported if I run python directly after instilling the setp.py but once I closed the terminal its not imported anymore

Cycling between "No module named functools_lru_cache" and "cannot import name cbook" errors

I am completely new to Python but I enjoyed it very much. I start with Python 2.7 before migrating to Python 3 since many applications for work have to do with Python 2.7.
I have quite sadly many version of python2.7 on my MacBook. One from Apple, one from Homebrew, one from Anaconda. I have pip version 18.0 installed.
I wanted to install many modules (scipy in particular) and I ran into the following problem.
On the console:
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 29 2018, 20:59:26)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> import matplotlib
I get the error message:
Traceback (most recent call last):
File "", line 1, in
import matplotlib
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/init.py", line 130, in
from matplotlib.rcsetup import defaultParams, validate_backend, cycler
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 29, in
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.py", line 28, in
from backports.functools_lru_cache import lru_cache
ImportError: No module named functools_lru_cache
I looked on the web and found the solution for that by typing:
pip install --user matplotlib
Now when I do:
>>> import matplotlib
I get the message:
Traceback (most recent call last):
File "", line 1, in
import matplotlib
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/init.py", line 126, in
from . import cbook
ImportError: cannot import name cbook
There is a confusion on the web about how to solve this problem. Is there still hope I can get back running?

DLL load failed for Tensorflow on Windows 10, Python 3.6 and 64-bit

The error: on trying to import Tensorflow from my Python 3.6 installation directory.
My Python 3.6 is installed here: C:\Python36.
All I did was python -m pip install tensorflow=1.5
To test the installation I ran import Tensorflow, but found this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python36\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Python36\lib\site-packages\tensorflow\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\Python36\lib\site-packages\tensorflow\core\framework\graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
File "C:\Python36\lib\site-packages\google\protobuf\descriptor.py", line 47, in <module>
from google.protobuf.pyext import _message
ImportError: DLL load failed: The specified procedure could not be found.
The options I tried:
Downgrading to Python 1.5
Getting the Windows redistributable that StackOverflow mentions here:
On Windows, running "import tensorflow" generates No module named "_pywrap_tensorflow" error
I tried another solution by reinstalling Python 3.6 with all the debugginf symbols and dlls but now I get the error :I tried another solution by reinstalling Python 3.6 with all the debugginf symbols and dlls but now I get the error : C:\Python36>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
2018-09-17 17:51:52.231635: I C:\tf_jenkins\workspace\rel-win\M\windows\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
print(sess.run(hello))
b'Hello, TensorFlow!' does this mean tensorflow worked or not?
I had multiple python paths in the PATH variable in my system's environment variables.
I installed Python 3.6.2 and then put the path in the environment variables, removing the other paths.
Thanks
i would suggest you just use anaconda if possible it works like a charm, and you don't have to manege anything, i too got that messege, and just desided to give up, and take the easy way. https://www.tensorflow.org/install/install_windows and here is the download page for anaconda https://www.anaconda.com/download/

ImportError: cannot import name '_remove_dead_weakref'

Yesterday updated my ubuntu 17.04 to ubuntu 17.10. any comments? Appear when I try to run server in pycharm. #django project.
bash -cl "/home/encuentrum/venv-encuentrum3/bin/python /usr/share/pycharm/helpers/pycharm/django_manage.py check /home/encuentrum/GitLab/encuentrum3/ENCUENTRUM/packers_"
Traceback (most recent call last):
File "/usr/share/pycharm/helpers/pycharm/django_manage.py", line 5, in <module>
from pycharm_run_utils import adjust_django_sys_path
File "/usr/share/pycharm/helpers/pycharm/pycharm_run_utils.py", line 4, in <module>
import imp
File "/home/encuentrum/venv-encuentrum3/lib/python3.6/imp.py", line 19, in <module>
from importlib._bootstrap import _ERR_MSG, _exec, _load, _builtin_from_name
File "/home/encuentrum/venv-encuentrum3/lib/python3.6/importlib/__init__.py", line 57, in <module>
import types
File "/home/encuentrum/venv-encuentrum3/lib/python3.6/types.py", line 171, in <module>
import functools as _functools
File "/home/encuentrum/venv-encuentrum3/lib/python3.6/functools.py", line 23, in <module>
from weakref import WeakKeyDictionary
File "/home/encuentrum/venv-encuentrum3/lib/python3.6/weakref.py", line 12, in <module>
from _weakref import (
ImportError: cannot import name '_remove_dead_weakref'
Maybe you have mixed your multiple Python installations, the newer version of weakref are not compatible with older version python binary, try to remove any one (the older one is recommended) of Python installation.
Analysis
For my case, I have installed older version Python (3.5.1) before, and upgrade my Debian installation. The newer Debian upgrade it's Python3.5 to 3.5.3 which have _remove_dead_weakref in _weakref in its Python binary
When I type $ where python3.5, I get
/usr/local/bin/python3.5
/usr/local/bin/python3.5
/usr/bin/python3.5
The /usr/local/bin/python3.5 is my own older installation, and /usr/bin/python3.5 is Debian offical Python3.5
When I update my Python3.5 installation by apt-get, apt-get execute python3.5 -E -S /usr/lib/python3.5/py_compile.py $files (post-install script) in the deb package.`, it triggers the weakref issue, here is my log
Setting up python3.5-minimal (3.5.3-1+deb9u1) ...
Traceback (most recent call last):
File "/usr/lib/python3.5/py_compile.py", line 6, in <module>
import importlib._bootstrap_external
File "/usr/lib/python3.5/importlib/__init__.py", line 57, in <module>
import types
File "/usr/lib/python3.5/types.py", line 166, in <module>
import functools as _functools
File "/usr/lib/python3.5/functools.py", line 23, in <module>
from weakref import WeakKeyDictionary
File "/usr/lib/python3.5/weakref.py", line 12, in <module>
from _weakref import (
ImportError: cannot import name '_remove_dead_weakref'
I tested Python 3.5.1 and Python 3.5.3 with same import action, here are the compares
Official Python 3.5.3 from apt-get
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
>>> from _weakref import _remove_dead_weakref
>>>
My own Python 3.5.1 installation
Python 3.5.1 (default, Apr 23 2016, 16:40:21)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from _weakref import _remove_dead_weakref
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name '_remove_dead_weakref'
>>>
So, I confirm that python3.5 in /usr/local/bin/ cannot use _remove_dead_weakref.
But which python did apt-get use in post-installation script? Try it.
$ which python3.5
/usr/local/bin/python3.5
So, here is why. The post-installation script use my custom installation of python, along with newer python library (/usr/lib/python3.5/weakref.py)
Fix it!
As I said, disable older version of python
sudo mv /usr/local/bin/python3.5 /usr/local/bin/python3.5.bak
Test
$ which python3.5
/usr/bin/python3.5
Adding to #Comzyh answer, this indeed is due to mixed python versions when an upgrade happen due to any reason. A quick fix is to remove your venv python binary i.e. rm <path-to-your-env>/bin/python and copying your system python binary to your venv like cp /usr/bin/python <path-to-your-env>/bin/python. This will fix the weak ref error

ImportError: No module named isodate

I cant import rdflib in python. error detailed:
Python 2.7.3 (default, Jun 27 2012, 23:48:21)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import rdflib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/rdflib/__init__.py", line 65, in <module>
from rdflib.term import URIRef, BNode, Literal, Variable
File "/usr/local/lib/python2.7/site-packages/rdflib/term.py", line 49, in <module>
from isodate import parse_time, parse_date, parse_datetime
ImportError: No module named isodate
I would be grateful if anybody can help.
Thanks.
If you actually install rdflib via pip, then its dependencies will come along with it (isodate included):
pip install -U rdflib
or
easy_install -U rdflib
Chances are you might have installed it directly from source, meaning you would have to take care of the deps yourself.
Information on installing pip if you dont have it already:
http://www.pip-installer.org/en/latest/installing.html
If you have easy_install, you can do: easy_install pip
It seems there is a dependency to isodate, so try installing that via your favorite PyPI-Installer (pip oder *easy_install*).

Categories