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.
Related
I am trying to web-scrape using requests and Python 3.10 from my Mac. But I receive this error just from trying to import requests:
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/__init__.py", line 58, in <module>
from . import utils
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/utils.py", line 30, in <module>
from .cookies import RequestsCookieJar, cookiejar_from_dict
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/cookies.py", line 159, in <module>
class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
Do I need to downgrade my python version, or what could I do?
The abstract base classes (abc's) in the collections module were moved to collections.abc in Python 3.3; in Python 3.10, the aliases were removed.
Your post doesn't make it clear what version of requests you're using or whether you require a new Python 3.10 feature, but hopefully one of the following options will work for you:
Create a Python 3.9 virtual environment and use the same version of requests, so those aliases are available.
See if requests has a newer version available that is compatible with Python 3.10. (Note many third-party libraries are not yet compatible.)
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 just tried to install Plotly using pip. I am running python from Anaconda and now anytime I attempt to run anything python I get the following errors and I have no idea how to fix it. I am running on Windows 7 64bit, Python3,4
PS Z:\> pip
Traceback (most recent call last):
File "C:\Anaconda3\Scripts\pip-script.py", line 3, in <module>
from pip import main
File "C:\Anaconda3\lib\site-packages\pip\__init__.py", line 11, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "C:\Anaconda3\lib\site-packages\pip\vcs\mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "C:\Anaconda3\lib\site-packages\pip\download.py", line 22, in <module>
from pip._vendor import requests, six
File "C:\Anaconda3\lib\site-packages\pip\_vendor\requests\__init__.py", line 58, in <module>
from . import utils
File "C:\Anaconda3\lib\site-packages\pip\_vendor\requests\utils.py", line 25, in <module>
from .compat import parse_http_list as _parse_list_header
File "C:\Anaconda3\lib\site-packages\pip\_vendor\requests\compat.py", line 77, in <module>
import simplejson as json
File "C:\Anaconda3\lib\site-packages\simplejson\__init__.py", line 112, in <module>
from .scanner import JSONDecodeError
File "C:\Anaconda3\lib\site-packages\simplejson\scanner.py", line 10, in <module>
c_make_scanner = _import_c_make_scanner()
File "C:\Anaconda3\lib\site-packages\simplejson\scanner.py", line 6, in _import_c_make_scanner
from simplejson._speedups import make_scanner
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 4: invalid start byte
PS Z:\>
This is an interaction between Anaconda's version of pip and the latest version of simplejson (which was installed when you installed Plotly).
As a workaround,
del C:\Anaconda3\lib\site-packages\simplejson
This will allow pip and Plotly to work again. Unfortunately if you ever upgrade Plotly this problem will happen again, so we will add a workaround to the Plotly requirements.txt file that prevents this from happening in future. (Plotly only actually needs simplejson on Python 2.6 systems.)
There was an Anaconda issue open related to this that I've commented on: https://github.com/ContinuumIO/anaconda-issues/issues/238
Plotly Python API issue re: finding a workaround so this doesn't happen again (or to other users): https://github.com/plotly/python-api/issues/197
As of version 1.6.10 for the plotly package, the simplejson and ordereddict packages are no longer dependencies.
TL;DR:
Python 2.6 should use:
pip install plotly[PY2.6]
While Python 2.7, 3.3, and 3.4 should still use:
pip install plotly
More Info:
If you're already hitting the issue in this post, you'll likely need to remove the simplejson package as discussed in answer scjody gave.
The simplejson and ordereddict packages were there to have common dependencies for Python 2.6 through Python 3.4. However, since simplejson clashes with anaconda, we now have an "extras" option for the pip install.
As usual, because the version of IPython we depend on doesn't support Python 2.6, there are still two optional requirements files which install matplotlib, IPython[notebook], etc.
optional_requirements.txt
optional_requirements-2-6.txt
Quotes Notes:
Depending on the shell you're using, you may need to wrap the install target in quotes ('') when using the extras for Python 2.6:
pip install 'plotly[PY2.6]'
I have installed protobuf in Python 3.4 and i pushed the compiled code pb_x_pb2.py into python34 folder. When i enter import pb_x_pb2.py it shows the following error.
>>> import pb_interface_pb2
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
import pb_interface_pb2
File "C:\Python34\pb_interface_pb2.py", line 5, in <module>
from google.protobuf import reflection
File "C:\Python34\lib\site-packages\google\protobuf\reflection.py", line 68, in <module>
from google.protobuf.internal import python_message
File "C:\Python34\lib\site-packages\google\protobuf\internal\python_message.py", line 848
except struct.error, e:
^
SyntaxError: invalid syntax
Protobuf doesn't really support python 3.x. For the imported libraries, try pip install protobuf-py3, a python 3 port of the package. You can also run the 2to3.py script from the Pythonxx\Tools\Scripts folder on the generated file.
Another option would be to download the newest version of the sources, and compile them yourself. I believe that the newest version is mostly compatible with both 2.x and 3.x
I am trying to run this example program - http://pysnmp.sourceforge.net/examples/1.x/snmpbulk.html
I am on Mac OS X, and I installed pysnmp by -
$ sudo /usr/local/bin/pip install pysnmp
Now when I run the program I get -
Traceback (most recent call last):
File "pysnmptest.py", line 2, in <module>
from pysnmp import msession
ImportError: cannot import name msession
UPDATE:
seems like pysnmp 4.x doesn't have msession, so I tried http://pysnmp.sourceforge.net/examples/4.x/v3arch/index.html
and now I get -
Traceback (most recent call last):
File "pysnmptest.py", line 2, in <module>
from pysnmp.entity.rfc3413.oneliner import cmdgen
File "/Library/Python/2.6/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 2, in <module>
from pysnmp.entity import engine, config
File "/Library/Python/2.6/site-packages/pysnmp/entity/engine.py", line 2, in <module>
from pysnmp.proto.rfc3412 import MsgAndPduDispatcher
File "/Library/Python/2.6/site-packages/pysnmp/proto/rfc3412.py", line 3, in <module>
from pysnmp.smi import builder, instrum
File "/Library/Python/2.6/site-packages/pysnmp/smi/builder.py", line 4, in <module>
from pysnmp.smi import error
File "/Library/Python/2.6/site-packages/pysnmp/smi/error.py", line 1, in <module>
from pyasn1.error import PyAsn1Error
ImportError: No module named pyasn1.error
The webpage also says they have dependencies on third-party libraries -
Latest PySNMP releases (4.x and later)
depend on the following:
ASN.1 library for Python used for
handling ASN.1 objects Python
Cryptography Toolkit used for SNMP
message authentication and encryption
How do I install them? and would it better to install from the tarball from webpage directly?
which version of pysmnp did you install? The example you're trying to run seems to be suited for the 1.x version of pysnmp.
Here I've found examples for the newest 4.x version. Note they don't use msession so I guess it was removed.
EDIT: Looks like now you have to install pyasn1 from here...
I don't use OSX so I don't know what's the better method for installing software on it. On ubuntu I just did apt-get install python-pysnmp and the whole thing was installed.
pyasn1 has been depended by pysnmp. So you could just type:
from pyasn1.error import PyAsn1Error