when i tried to search bookdetails from library of congress using python with the help of z3950 module, I got following error
from PyZ3950 import zoom
File "/usr/local/lib/python2.6/dist-packages/PyZ3950/zoom.py", line 72, in <module>
from PyZ3950 import z3950
File "/usr/local/lib/python2.6/dist-packages/PyZ3950/z3950.py", line 72, in <module>
from PyZ3950 import asn1
File "/usr/local/lib/python2.6/dist-packages/PyZ3950/asn1.py", line 2009, in <module>
import profile
ImportError: No module named profile
please help me for a solution
This blog post suggests that it is not part of the default install of Python on Ubuntu 11.04. It says:
You will need to enable the multiverse repository first.
The solution is to install the python-profiler package, i.e. do this command:
sudo aptitude install python-profiler
Then you can use python profile as normal.
Related
Smartsheet API beginner using python is in need of help
Hi, everyone. I am working on smartsheet API and am trying to follow the website to get some exercise first from https://smartsheet-platform.github.io/api-docs/#sdks-and-sample-code.
I have python 2.7.15 on Mac, so the first step I did was to download the pip folder, and type "pip install smartsheet-python-sdk" on my terminal to install pip. Then I used my .py file to test out the code, I ran the first line import smartsheet and there is an error already.
The message I got is below, any suggestions will be appreciated:
Traceback (most recent call last):
File "/Users/my name /Desktop/charity.py", line 6, in <module>
import smartsheet
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/smartsheet/__init__.py", line 31, in <module>
from .smartsheet import Smartsheet, fresh_operation, AbstractUserCalcBackoff # NOQA
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/smartsheet/smartsheet.py", line 34, in <module>
from .models import Error, ErrorResult
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/smartsheet/models/__init__.py", line 21, in <module>
from .access_token import AccessToken
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/smartsheet/models/access_token.py", line 20, in <module>
from ..types import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/smartsheet/types.py", line 26, in <module>
from enum import Enum
ImportError: No module named enum
enum module was added in Python 3.4 but you're on Python 2.7. The smartsheet platform claims to support Python 2.7 but it also requires the import of enum for it to work.
You can submit an issue to the project and hope that they fix it or upgrade to Python 3.4 and beyond.
Per a previous answer, the error is due to using Python 2, while enum was added in Python 3.4. However, there is a backport if you need to use Python 2 for some reason.
Simply install with pip install enum34. I tested smartsheet with the enum34 library using Python 2.7.16 and was successful.
I have been using Jupyter notebook in AWS EMR when I run a program which requires graphical representations. I get this error:
No module named 'tkinter'
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/seaborn/__init__.py", line
6, in <module>
from .rcmod import *
File "/usr/local/lib/python3.4/site-packages/seaborn/rcmod.py", line 5,
in <module>
from . import palettes, _orig_rc_params
File "/usr/local/lib/python3.4/site-packages/seaborn/palettes.py", line 12, in <module>
from .utils import desaturate, set_hls_values, get_color_cycle
File "/usr/local/lib/python3.4/site-packages/seaborn/utils.py", line 11, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib64/python3.4/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/local/lib64/python3.4/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
[backend_name], 0)
File "/usr/local/lib64/python3.4/site-packages/matplotlib/backends/backend_tkagg.py", line 4, in <module>
from . import tkagg # Paint image to Tk photo blitter extension.
File "/usr/local/lib64/python3.4/site-packages/matplotlib/backends/tkagg.py", line 5, in <module>
from six.moves import tkinter as Tk
File "/usr/local/lib/python3.4/site-packages/six.py", line 92, in __get__
result = self._resolve()
File "/usr/local/lib/python3.4/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/local/lib/python3.4/site-packages/six.py", line 82, in _import_module
__import__(name)
ImportError: No module named 'tkinter'
You should run matplotlib with a non-interactive backend on a EC2 server as EC2 is headless. Configure your matplotlibrc file with this line.
backend : agg
To know more about this file, follow this link.
I believe you need to install the python3-tk module. If you're using a debian-based distro then run apt-get install python3-tk from the command line.
I just looked at this on a CentOS 7 VM (closest thing to your environment that I have set up right now). Because you are not using a software collection (definitely recommended), it looks like Tkinter can be installed with:
sudo yum install python33-python-tkinter.x86_64
But it looks like that is for Python 3.3 whereas you are using Python 3.4, so I'd suggest trying:
sudo yum install python34-python-tkinter.x86_64
Finding Packages
If that does not work, the easiest way I know of to find the appropriate package is to do:
yum search tkinter | less
...and see what packages that turns up.
Software Collection
If you go the route of software collections, you would need to install the appropriate Python distribution (see the Software Collections site here), then install the appropriate tkinter version. For me, yum search tkinter brings up:
...
rh-python34-python-tkinter.x86_64
rh-python35-python-tkinter.x86_64
rh-python36-python-tkinter.x86_64
...
These are for the software collections and correspond to Python 3.4, 3.5, and 3.6.
I am trying to use this sample code from the Google Natural Language API to get a sentiment score back. However, each time I run the code, I get an "ImportError: cannot import name language." error on the first line.
I have pip installed the library, tried uninstalling and reinstalling, made the credentials on the console (the API is shown to be enabled) and looked at this tutorial too and completed those steps in the answer: Google sentiment analysis - ImportError: cannot import name language. It hasn't helped. Is there anything else I can try?
from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types
client = language.LanguageServiceClient()
text = u'Hello, world!'
document = types.Document(
content=text,
type=enums.Document.Type.PLAIN_TEXT)
sentiment = client.analyze_sentiment(document=document).document_sentiment
print('Text: {}'.format(text))
print('Sentiment: {}, {}'.format(sentiment.score, sentiment.magnitude))
I also have pasted this into my terminal with the proper path.
export GOOGLE_APPLICATION_CREDENTIALS="/....(my path)/service_key.json"
Stack trace:
Traceback (most recent call last):
File "lang.py", line 3, in <module>
from google.cloud import language
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google/cloud/language.py", line 17, in <module>
from google.cloud.language_v1 import LanguageServiceClient
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google/cloud/language_v1/__init__.py", line 17, in <module>
from google.cloud.language_v1 import types
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google/cloud/language_v1/types.py", line 18, in <module>
from google.api_core.protobuf_helpers import get_messages
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google/api_core/__init__.py", line 20, in <module>
from pkg_resources import get_distribution
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3161, in <module>
#_call_aside
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3145, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3189, in _initialize_master_working_set
for dist in working_set
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3189, in <genexpr>
for dist in working_set
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2715, in activate
declare_namespace(pkg)
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2274, in declare_namespace
_handle_ns(packageName, path_item)
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2209, in _handle_ns
loader.load_module(packageName)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pkgutil.py", line 246, in load_module
mod = imp.load_module(fullname, self.file, self.filename, self.etc)
File "/.../lang.py", line 3, in <module>
from google.cloud import language
ImportError: cannot import name language
This seems to be a duplicate of this question:
Google sentiment analysis - ImportError: cannot import name language
For me, wasn't enough to upgrade google-api-python-client and google-cloud
Instead, what solved my problem was:
!pip install google-cloud-language
Besides, when you upgrade google api libraries, an incompatibility error shows up with awsebcli library (from AWS).
The explanation:
If you look at the stack trace, the import of google.cloud.language is actually working and it is not circular. The second and third items in the stack trace are langauge.py successfully asking for the items underneath, ultimately delegating off to google.api_core (which is our runtime behind all of these libraries).
The fifth line in the trace is the interesting one: it corresponds to line 20 of google/api_core/__init__.py and it is from pkg_resources import get_distribution. Everything that comes after that is an attempt to make that import work; since it does not, the ImportError bubbles up, and the previous imports cascade-fail.
Probable solution:
Make sure your pip and setuptools are up to date. Namespace packing is notoriously tricky so you have to have a pretty recent version. Just issue pip install --upgrade setuptools pip.
Gordian solution:
Have you considered Python 3? :-)
Troubleshooting:
If that does not work (and Python 3 is not an option), the next thing we need to know is what that final failure is. The penultimate call in the track is a call to imp.load_module(fullname, self.file, self.filename, self.etc). We will need to know what those values are to troubleshoot further. To get them, add import pdb ; pdb.set_trace() immediately before the import in your code that is failing. This will toss you into a debugger at that point. Use n (next) and s (step into function) to move through the code (you can get variable values and such by typing them in the REPL). If you can print the values of what is trying to be imported specifically, we can assist you further.
Try to upgrade pip:
python -m pip install --upgrade pip
Then upgrade the Google packages:
pip install --upgrade google-api-python-client
pip install --upgrade google-cloud
If using Google Cloud Functions, make sure google-cloud-language is specified in the requirements.txt tab:
The following solved my issue:
pip install google-cloud-translate
Then i ran the following code smoothly:
from google.cloud import translate
reference: https://pypi.org/project/google-cloud-translate/
My issue is possibly similar to link
but thought I'd ask jic. I'm on osx and trying to use jedi-vim. I installed jedi using pip and then jedi-vim by cloning into the dir that my vim config uses for loading packages. this one for reference. When I start vim with a python program I get the "Please install Jedi if..." message. I cloned vim 74 and configured with +python and +conceal. After still getting the error I looked into the code and found it was an import error.
As an aside, this isn't the best help message. Better might be "Unable to import jedi. Have you installed Jedi?"
I tried import jedi from within vim, as :python import jedi
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/jedi-0.9.0- py2.7.egg/jedi/__init__.py", line 41, in <module>
from jedi.api import Script, Interpreter, NotFoundError, set_debug_function
File "/usr/local/lib/python2.7/site-packages/jedi-0.9.0 py2.7.egg/jedi/api/__init__.py", line 16, in <module>
from jedi.parser import Parser, load_grammar
File "/usr/local/lib/python2.7/site-packages/jedi-0.9.0-py2.7.egg/jedi/parser/__init__.py", line 21, in <module>
from jedi.parser import tree as pt
ImportError: cannot import name tree
If this is a build issue, is there a good reference for building vim on mac?
I am trying to install Django-1.5.5 on windows 7. I have installed it but when I try to punch in "django-admin.py startproject mysite" I get following error:
C:\Users\DIPANSHU>django-admin.py startproject mysite
Traceback (most recent call last):
File "C:\Django-1.5.5\django\bin\django-admin.py", line 2, in <module>
from django.core import management
File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
9, in <module>
from django.core.management.base import BaseCommand, CommandError, han
fault_options
File "C:\Python27\lib\site-packages\django\core\management\base.py", lin
in <module>
from django.utils.encoding import force_str
File "C:\Python27\lib\site-packages\django\utils\encoding.py", line 10,
dule>
from urllib import quote
File "C:\Python27\lib\urllib.py", line 26, in <module>
import socket
File "C:\Python27\lib\socket.py", line 47, in <module>
import _socket
ImportError: DLL load failed: The specified procedure could not be found.
Previously, I tried with Django-1.4.2 but problem was same. I am having Python27.Please assist.
Yups! Finally got it! So here's what I did:
Removed python completely and installed it again.
adjust my PATH environment variable to include paths to the Python executable & additional scripts.
Installed Setuptools
Installed pip using easy_install pip.
Installed Django using pip install django.
Note: If your Python is installed in C:\Python27\, the following paths need to be added to PATH: C:\Python27\;C:\Python27\Scripts;
Reference: https://docs.djangoproject.com/en/dev/howto/windows/
Thanks a lot for your valuable inputs and bearing with me! :-)
I would make sure that DJango is installed by running
python -c "import django; print(django.get_version())"
https://docs.djangoproject.com/en/1.6/intro/tutorial01/
I found the Django tutorial on their site to be very good
Also what exactly are you typing into the command prompt ? You should simply be in directory C:\Users\DIPANSHU> in the command shell
EDIT: you should be in the directory where you installed Django