configparser stopped working and ConfigParser is OK! on Python 2.7 - configparser

I have been using my computer,
running experiments with Python 2.7 and configparser worked fine!
Today it decided to stop working
and I changed configparser to ConfigParser, and
it worked! Still on Python 2.7.
Any idea how to revert that? Make it work again with configparser?
I do not want to go through all my code
and change them. On top of that it is irritating that
all of a sudden it decided to stop working!
Thanks

You can import the module under a different name:
import ConfigParser as configparser
This change was introduced in Python 3.0 back in 2007, it is documented in the "What's New In Python 3.0" as well as the PEP 3108 document in section "PEP 8 violations". A few modules, including ConfigParser, were renamed to comply with Python's PEP8 style guide. Quote:
PEP 8 specifies that modules "should have short, all-lowercase names" where "underscores can be used ... if it improves readability".

Related

ModuleNotFoundError: No module named 'yaml'

I have used a YAML file and have imported PyYAML into my project.
The code works fine in PyCharm, however on creation of an egg and running the egg gives an error as module not found on command prompt.
You have not provided quite enough information for an exact answer, but, for missing python modules, simply run
py -m pip install PyYaml
or, in some cases
python pip install PyYaml
You may have imported it in your project (on PyCharm) but you have to make sure it is installed and imported outside of the IDE, and on your system, where the python interpreter runs it
I have not made an .egg for some time (you really should be consider using wheels for distributing packages), but IIRC an .egg should have a requires.txt file with an entry that specifies dependency on pyyaml.
You normally get that when setup() in your setup.py has an argument install_requires:
setup(
...
install_requires=['pyyaml<4']
...
)
(PyYAML 4.1 was retracted because there were problems with that version, but it might be in your local cache of PyPI as it was in my case, hence the <4, which restricts installation to the latest 3.x release)

install pygtk for python 3.6.1 on Windows 10

Since PIL.ImageGrab() gave me some problems, I read further into the topic and it seems that gtk is the better solution for making Screenshots.
But I don't understand which packages are actually working and which are deprecated.
trying
pip install pygtk
gives me
ERROR: Could not import dsextras module: Make sure you have installed pygobject.
pygobject doesn't exist, installing gobject doesn't help.
I tried some variants of the module name like python3- or just 3 at the end, but I don't seem to get the right one.
The full chat session about this is here. The original solution can be read here, especially the comment made by #cdarke.
So anyway, the solution is to use Python3.5 intead of 3.6 or newer, at least until MSYS2 is updated.
As a sidenote, you really don't want to use pygtk (which is based on Gtk2). Use pygobject like such:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
for GTK+, you have to do the following:
from gi.repository import Gtk
and not:
import gtk

No module named keras

I have successfully installed keras after much struggle in the directory /usr/local/lib/python3.5/dist-packages(by deafult it has been installed there). But whenever i am trying to import or trying to modify the keras backend it says No mudule named keras. What am I doing wrong here and how will I modify the keras.json file in these current conditions?
you should be able to edit keras.json directly. it should be at ~/.keras/keras.json .
also it seems you installed keras for python3 but are trying to use it with python(2).
try using pip instead of pip3 (or python3 instead of python). :)
see details here.
What am I doing wrong here?
The problem is that you start Python 2, but you installed it for Python 3. Your system has likely both Python versions, but you installed it only for one.
If you want to start Python 3, try python3:
python3 -c "from keras import backend; print(backend._BACKEND)"
How do I modify the keras.json file?
Open ~/.keras/keras.json with the editor of your choice. For example:
nano ~/.keras/keras.json

How do I import Zbar into my Python 3.4 script?

I am pretty new to programming, and have never used Zbar before. I am trying to write a simple script that will allow me to import Zbar and use it to decode a barcode image. I already have a script set up to decode text from images that uses Pytesseract and Tesseract OCR, but I need to be able to decode barcodes as well. I have Windows 7 32 bit, and and am using Python 3.4. I have already installed Zbar and have used it from the command line successfully to decode their barcode sample. I have tried using >pip install zbar, but I keep getting the error:
"fatal error C1083: Cannot open include file: 'zbar.h': No such file or directory
error: command 'C:\Program Files\Microsoft Visual Studio 10.0\VC\BIN\cl.exe' failed with exit status 2"
Getting the pytesseract OCR was painless but I have wasted a lot of time on this barcode portion of it, any help or alternatives would be much appreciated.
Seven months later you accepted the best answer, a simple solution for
python3.4+ on Windows OS appeared. A ctypes-based wrapper around the zbar barcode reader, a package named pyzbar. If you are on Linux, you need to install libzbar0 but you said you are using Windows and the zbar library is included as dll with the Windows Python wheels. Today, all you need to do is launch:
pip install pyzbar
References for the package:
https://pypi.python.org/pypi/pyzbar
https://github.com/NaturalHistoryMuseum/pyzbar/
I thought I'd share my explorations and discoveries in relation to this problem, even though #ltadams21 has found a workaround.
The short answer: You can't. The zbar module is only compatible with Python 2. The incompatibilities are at the level of the Python C API, which is deep magic beyond my ken.
There's a bug report for this. In the meantime, use the os.system workaround that #ltadams21 posted, or maybe try zbarlight instead? (I haven't tried it myself, because it says it only reads QR codes, and I need something that reads EAN barcodes.)
The long answer: You can follow along with these steps, which represent my best efforts to get it working, but (spoiler alert) it still won't work at the end.
(Re)install zbar for Windows (zbar-0.10-setup.exe), making sure to tick the "Development Headers and Libraries" option.
Download and extract the zbar Python package (zbar-0.10.tar.bz2).
Open setup.py in your preferred text editor.
Scroll to the bottom, find the line that starts libraries, and insert a new line below it, like so (checking that the path is the same on your system as it is on mine):
libraries = [ 'zbar' ],
include_dirs = ['C:/Program Files (x86)/ZBar/include'],
Open a command prompt inside the extracted package and run python setup.py install.
Observe that the new errors now relate to PyIntObject and PyInt_Type. Discover that these are Python 2-only objects.
If desperate, try to re-#define them to use PyLongObject and PyLong_Type instead. Fail, because of course it's not that easy. Bang head against keyboard (gently).
Give up, and use the os.system workaround that #ltadams21 posted.
Forget wrestling with all of the wrappers. The easiest solution for me was to simply use
import os
os.system(r'D:\Winapps\Zbar\bin\zbarimg.exe -d d:\Winapps\Zbar\Examples
\barcode.png')
Worked instantly. Hope this helps anyone else struggling with that issue.
As of November 2016, there is the package pyzbar. To import Zbar for python3.4+ on Windows OS, all you need to do is launch
pip install pyzbar
This is possible because pyzbar is a ctypes-based wrapper around the zbar library that is included as dll with the Windows Python wheels.
The ZBar for python says you need to have the ZBar library installed for it to work. http://zbar.sourceforge.net/download.html
I found an easy solution for 3.4+. First install pyzbar
pip install pyzbar.
Then the below should work
import pyqrcode
from pyzbar.pyzbar import decode
from PIL import Image
qr = pyqrcode.create("HORN O.K. PLEASE.")
qr.png("horn.png", scale=6)
decode(Image.open('horn.png'))
print(qr.data)

How to install Pygame on Portable Python 3.2.5.1

I know that similar- questions about installing modules in Portable Python have been
asked but I have looked at all of them and another website. I didn't have success.
For me, I wanted to install Pygame on Portable Python 3.2.5.1 (on a memory stick). I nearly
managed to install it successfully but when I typed import pygame into the shell window,
there was a weird error in one of the files, displayed in the shell. See image below:
Update: Portable Python at time of writing has been discontinued (not being developed anymore)
and there are other alternatives available in suggested links on their website or internet search
engine query results. I have managed to add the Pygame Python module to my version
of one of these continuing projects so this question is not of use to me anymore.
I had this same problem today. I may have managed it. This is what I did:
I installed pygame to an empty folder so I could see all the things it needed. this was two folders:
Include>pygame and
Lib>site-packages
I went to Lib>site-packages and copied all the things there, then pasted them into
G:\Portable Python 3.2.5.1\App\Lib\site-packages
I also copied all the things in:
G:\Include\pygame
and pasted them into:
G:\Portable Python 3.2.5.1\App\include
from a quick play, this seems to work.
Although it isn't really the proper answer I was looking for a while ago when I posted the question (how to install Pygame on Portable Python 3.2.5.1), I have a possible answer for my question that could work.
It is possible (although I haven't personally tested it yet) run a Python
program using Portable Python and with the Pygame library folder stored in the directory the program is stored in. Python's module search path includes the current directory (of the running file) so import pygame would import it.
This question is old and maybe this is a possibility that was not possible at this time but simply:
From a command prompt go to your Portable Python's python.exe folder with cd <path to Portable Python>\App\Python,
Run: .\python.exe -m pip install pygame,
Now you have pygame module installed, you can check in your <path to Portable Python>\App\Python\Lib\site-packages that you have now pygame.
Note: I used Portable Python from here, version 3.10.5 at the time I wrote this.

Resources