I am using and importing ConfigParaser
import ConfigParser
config = ConfigParser.RawConfigParser()
config.read('Config.properties')
timeout_val=config.get('Section', 'commandtimeout')
and install it using,
pip install ConfigParser
While running the python script getting below mention error.
Traceback (most recent call last):
File "system_offline.py", line 41, in <module>
import ConfigParser
ImportError: No module named 'ConfigParser'
Now, my question is if run the same program using python 2.7 at the same system, above import statement works with out issue.
Wondering what needs to be done for this program to run with python3?
Edit: While using python 2.7 it is working but with python3, i am getting above mention error.
The ConfigParser module was renamed to configparser in Python 3.0.
If you are using python 3, this will work, the module was renamed
import configparser
config = configparser.RawConfigParser()
Related
I'm trying to use the Python YouTube Data API Python script that allows to upload a video: https://developers.google.com/youtube/v3/guides/uploading_a_video#Sample_Code. Note that it's compatible Python 2.x, not 3.X. So I've updated its code by replacing the first import ( import httplib ) by this import: import http.client .
When I run this script, the following error is shown:
Traceback (most recent call last):
File "/home/xzerzxez/pycharm_projects/zerde/upload_video.py", line 3, in
import http.client
ImportError: No module named http.client
Process finished with exit code 0
PyCharm's used environment: my Ubuntu's one
Python version: /usr/bin/python3.6
Pertinent packages installed: httplib2, request, requests
Available packages to install: micropython-http.client, pycopy-http.client, yieldfrom.http.client
How to solve this problem?
Edit: of course I also made other littles changes to the code to make it compatible Python 3.X, but it's off-topic :-) .
Solved by changing the shebang to #!/usr/bin/python3
I previously had Python 2.7 installed and was making calls like this:
api = jsonrpclib.Server('my host')
api.someFunctionCall()
I then upgraded to Python 3.5.2 and now when I run the code above, I'm receiving this message:
Traceback (most recent call last):
File "C:\login\login.py", line 1, in <module>
import jsonrpclib
File "C:\Python3.5.2\lib\site-packages\jsonrpclib\__init__.py", line 5, in <module>
from jsonrpclib.jsonrpc import Server, MultiCall, Fault
ImportError: No module named 'xmlrpclib'
I checked my installation and I do indeed have the xmlrpc lib:
c:\Python3.5.2\Lib\xmlrpc
What am I doing wrong?
Python 3.x has relocated the xmlrpclib module. Per the Python 2.7 xmlrpclib documentation:
"The xmlrpclib module has been renamed to xmlrpc.client in Python 3. The 2to3 tool will automatically adapt imports when converting your sources to Python 3."
It looks like the author of jsonrpclib has an open issue for Python 3 support, but hasn't responded or taken pull requests in a year. You may want to give the jsonrpclib-pelix fork a look for Python 3 support.
I'm trying to run the hello world tutorial for the Google app engine in Go language. The GAE SDK for go is based on python 2.5, which I installed. I then had to install openssl, but now when I try to run my sample application on the SDK, I get the following error:
ImportError: No module named _md5
I even tried a simple import md5 & import hashlib from the python interpreter interface, and i still get the same error
>>> import hashlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.5/hashlib.py", line 133, in <module>
md5 = __get_builtin_constructor('md5')
File "/usr/local/lib/python2.5/hashlib.py", line 60, in __get_builtin_constructor
import _md5
ImportError: No module named _md5
Does anybody know a workaround for this? Thank you!
I have a feeling that this problem is really about python installation than anything else
Your problem has nothing to do with GAE, or the SDK. I have faced this before. If you tried to install your custom version of python (on Ubuntu), then you land up with such issues. You should uninstall the custom python using checkinstall. More details can be found about there here: Uninstall python built from source?.
Just use the default python and you'll be fine!
I'm trying to configure and run SVN post-commit hook sending mails. I've downloaded class mailer.py, installed Python 2.7 and svn-win32 bindings for svn. The machine is Windows-7 64 bit, the Python is 32 bit. Now the mailer.py ends with error, which is caused by import problem.
When I in python console type "import svn.core" I have following error:
>>> import svn.core
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\tools\Python27\lib\site-packages\svn\core.py", line 19, in <module>
from libsvn.core import *
File "c:\tools\Python27\lib\site-packages\libsvn\core.py", line 5, in <module>
import _core
ImportError: No module named _core
while in directory site-packages/libsvn are files such as: _core.dll
I've installed other bindings, pysvn, that was installed correctly, but as far as I've noticed, it's the totally other API so I can't use that for python.py
Does someone had similar problem and knows how to deal with it?
The Python bindings need to load the native Subversion libraries (DLL's). If your Python is 32-bit then you would need 32-bit versions of the native Subversion libraries on PATH.
I have problem like this. Trouble was that python just can not import this library (svn.core and other).
I just make:
import sys
sys.path.append("C:\csvn\lib\svn-python").
My file core.pyc was in C:\csvn\lib\svn-python\svn. Hope it helps somebody. Such behacior for me is strange because there is no "init.py" or "init.pyc" file in svn-python directory. But it works.
I decided to develop my home project in python 3.x rather than 2.x. So I decided to check, if it works under 3.1. I run python3.1 above my package directory and then:
>>> import fathom
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "fathom/__init__.py", line 3, in <module>
from schema import Database
ImportError: No module named schema
when I enter fathom directory however schema can be imported:
>>> import schema
Also when I run python2.6 above my package directory I can do this:
>>> import fathom
My __init__.py has following import:
from schema import Database
from inspectors import PostgresInspector, SqliteInspector, MySqlInspector
Should I add something for python3.1?
Did you try a relative import?
from . import schema
from .inspectors import PostgresInspector
Works in Python 2.6 as well.
The 2to3 script can help you pinpoint more of these problems.