Zlib and binascii don't build with Python3.6 - python-3.x

I've been trying to build Python3.6.1 from source code on Ubuntu 14.04. The sequence of commands is as recommended by README:
./configure
make
make test
The latter crashes because it cannot import binascii. In its output there is a following:
Following modules built successfully but were removed because they could not be imported:
binascii zlib
Trying to skip make test and start make install I have it crashing after failing to import zlib. Some folks in the Ubuntu forums suggested to update all the zlib's packages from repositories. That doesn't help. How do I fix this?

Try to install zlib from the source code(http://www.zlib.net/) manually (not via yum/apt-get/brew...) might be helpful.
I have tried the Python3.6.1 building in my mac dev and also encountered your problem. It complains following message after making.
Python build finished successfully!
The necessary bits to build these optional modules were not found:
... zlib ...
And I can't import zlib in interactive shell too.
>>> import zlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'zlib'
I have solved the problem by the following steps.
visit http://www.zlib.net/ and download zlib-1.2.11.
install zlib (decompress, configure, make, make install).
reinstall Python3.6.1 (make clean, make).
I found the making process did not complain about zlib missing anymore and I could import zlib successfully in the shell.
Actually, to solve this kind of problems, we might find some hints from the source code.
We can find the following code in "setup.py" and the comments are pretty helpful. We can modify the code with debug information to locate where the problem really is (for me, it is because the first if check fails due to zlib.h missing).
# You can upgrade zlib to version 1.1.4 yourself by going to
# http://www.gzip.org/zlib/
zlib_inc = find_file('zlib.h', [], inc_dirs)
have_zlib = False
if zlib_inc is not None:
zlib_h = zlib_inc[0] + '/zlib.h'
version = '"0.0.0"'
version_req = '"1.1.3"'
if host_platform == 'darwin' and is_macosx_sdk_path(zlib_h):
zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
with open(zlib_h) as fp:
while 1:
line = fp.readline()
if not line:
break
if line.startswith('#define ZLIB_VERSION'):
version = line.split()[2]
break
if version >= version_req:
if (self.compiler.find_library_file(lib_dirs, 'z')):
if host_platform == "darwin":
zlib_extra_link_args = ('-Wl,-search_paths_first',)
else:
zlib_extra_link_args = ()
exts.append( Extension('zlib', ['zlibmodule.c'],
libraries = ['z'],
extra_link_args = zlib_extra_link_args))
have_zlib = True
else:
missing.append('zlib')
else:
missing.append('zlib')
else:
missing.append('zlib')

Related

How can I resolve python requests package import error?

I am new to python and am having trouble getting the python requests package to run. I have searched around for answers, but it seems that the question is most often answered with instructions on installing the requests package, which you will see I have already done.
Before I start, my specs are as follows:
OS: MacOSX Catalina 10.15.7
Shell: iTerm2 Build 3.3.12
Python Versions:
System: 2.7.16
pyenv: 3.9.0
Use Case: I am experimenting with web scraping and am attempting to write a simple program that will scrape some data from a local car dealership's website (e.g. scrape info on cars listed under $20k).
Before starting the project, I installed the requests package with the following command:
% pip3 install requests
I then opened up a vim file and wrote the following, just to ensure that the requests package was working properly:
import requests
URL = 'cardealerurl.com/query'
page = requests.get(URL)
I saved the file as carScrape.py.
Then I went beck to the shell and executed the following:
python carScrape.py
on execution, I receive the following error message:
Traceback (most recent call last):
File "carScrape.py", line 1, in <module>
import packages.requests
ImportError: No module named packages.requests
Any help with this would be greatly appreciated. If more information is needed, please just let me know and I will provide whatever I can. Thank you all so much.
I was able to solve this by running the following commands:
% sudo -H pip3 uninstall pip
% python3 -m ensurepip
% pip3 install requests
This was after a pretty long chunk of time trying other solutions that did not work. I also had to start a new shell to get rid of the error message.

Is it possible to install python libraries with pip programmatically?

Let me explain what I want to do.
The list of libraries I want installed is listed in a .txt file.
My script reads the list from the file sequentially, and if the script isn't installed, it installs it via pip, or if it is already installed, checks the version and updates it if necessary.
I googled it up but didn't find how to do that. Can you offer any help or guidance?
Yes you can. Try this, here is an example of one module which is hard coded
import os
import subprocess
import sys
get_pckg = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
installed_packages = [r.decode().split('==')[0] for r in get_pckg.split()]
required_packeges = ['shopifyAPI'] // Make a change here to fetch from file
for packg in required_packeges:
if packg in installed_packages:
pass
else:
print('installing package')
os.system('pip install ' + packg)
First i will fetch all installed modules and then i will check my required module is installed or not if not then it will install it.
Yes, you can. Python module os does support running script programmatically. Since I don't know how your file structure looks like, I guess you can read the file and run the script sequentially.
import os
os.system("pip install <module>")
Use Following to install lib. programmatically.
import pip
try:
pip.main(["install", "pandas"])
except SystemExit as e:
pass

opencv import issue and double install

Previously ROS was installed in my system which requires opencv for its implementation and now I am using anaconda in which I need to use the opencv library once again. While writing python code import cv2 throws an error module not found.
Is there any way to use that opencv library which ROS installed in anaconda
Although I installed opencv once again using conda.
$conda install -c conda-forge opencv
however opencv-3.3 was installed using above command. Now my python code is showing different import error as shown below:
ImportError Traceback (most recent call last)
<ipython-input-9-6b49ad4d4ca5> in <module>()
1 from random import shuffle
2 import glob
----> 3 import cv2
4 shuffle_data = True # shuffle the addresses before saving
5 hdf5_path = 'dataset.hdf5' # address to where you want to save the hdf5 file
ImportError: /home/kamal/ros_catkin_ws/install_isolated/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type
How can I particularly specify which opencv library to use. What env variables I need to change.
Any help will be appreciated.
uncommenting the line source /home/user/ros_catkin_ws/install_isolated/share/setup.bash in the .bashrc file dosen't help. You also need to remove the extrasys.path added by the ROS environment.
In a python console
import sys
print (sys.path)
you will see multiple paths related to ROS
then remove the unwanted part of the path by
sys.path.remove('unwanted_path')
This will solve the problem but now ROS will not work. To make it work you need to append the removed path again.
If someone has a better approach please answer.

Can't install lxml with Python3.5, Windows 10, 32 bit

Python 3.5 on Windows 10, 32-bit box; all I want to do is run this:
import quandl
import pandas as pd
import html5lib
import lxml
# retrieve web page with list of 50 states
fiddy_states = pd.read_html('https://simple.wikipedia.or /wiki/List_of_U.S._states')
But for the life of me I can't seem to get a properly installed lxml, which is required by pd.read_html. Following advice from several online sources I have MinGW installed in my system and I have also added the following to C:\Python35-32\Lib\distutils\distutils.cfg:
[build]
compiler=mingw32
I have MinGW installed and included in PATH. I have tried installing lxml using both pip3 as well as the binaries found at Unofficial Windows Binaries for Python Extension Packages.
Here's all installed packages:
['beautifulsoup4==4.4.1', 'cffi==1.6.0', 'cryptography==1.3.2', 'cycler==0.10.0', 'cython==0.24', 'html5lib==0.9999999', 'idna==2.1', 'inflection==0.3.1', 'lxml==3.4.4', 'matplotlib==1.5.1', 'more-itertools==2.2', 'ndg-httpsclient==0.4.0', 'numpy==1.11.0', 'pandas-datareader==0.2.1', 'pandas==0.18.1', 'pip==8.1.2', 'pyasn1==0.1.9', 'pycparser==2.14', 'pyopenssl==16.0.0', 'pyparsing==2.1.4', 'python-dateutil==2.5.3', 'pytz==2016.4', 'quandl==3.0.1', 'requests-file==1.4', 'requests==2.10.0', 'scikit-learn==0.17.1', 'setuptools==18.2', 'six==1.10.0']
As shown above, lxml==3.4.4 appears to be installed, however when I try to run the line containing pd.read_html I get the following error message:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\Jose Manuel\AppData\Local\Programs\Python\Python35-32 \lib\site-packages\pandas\io\html.py", line 874, in read_html
parse_dates, tupleize_cols, thousands, attrs, encoding)
File "C:\Users\Jose Manuel\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pandas\io\html.py", line 726, in _parse
parser = _parser_dispatch(flav)
File "C:\Users\Jose Manuel\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pandas\io\html.py", line 685, in _parser_dispatch
raise ImportError("lxml not found, please install it")
ImportError: lxml not found, please install itenter code here
Your help is very much appreciated
I have been struggling with this today. I found, elsewhere on stackoverflow.com, this two-part and quick solution, which resulted in python no longer complaining when I tried to use lxml:
go to this repository and download a version which matches your Python installation (the version number, and 32- vs 64-bit. I use Python 3.5.1 64-bit, installed on Windows 10, so on that page, I chose lxml-3.6.0-cp35-cp35m-win_amd64.whl. You say you have 32-bit Python, so use a version that matches that (like lxml-3.6.0-cp35-cp35m-win32.whl.
My download directory is d:\Downloads. Python must be in your PATH environment variable for the next step to work. Use a command like the following, changing "D:\Downloads" to the pathname to your download directory. Then, at a DOS prompt, type:
python -m pip install "D:\Downloads\lxml-3.6.0-cp35-cp35m-win_amd64.whl" lxml-3.6.0-cp35-cp35m-win_amd64.whl

Python, PySerial and cx-freeze

Trying to learn cx-freeze. I have a python program that I am trying freeze to exe.
I use PySerial and no matter how I try to include win32 nothing seems to help. I use Python 3.2 and win7.
I have searched the web thin, and others have had the same problem, but no solution seems to be appearing. But I doubt that no one have succeeded in cx_freezing something that uses PySerial.
I am completely stuck. Any help would be much appreciated
Error:
Traceback (most recent call last):
File "C:\Python32\lib\site-packages\
7, in <module>
exec(code, m.__dict__)
File "snapper.py", line 8, in
File "C:\Python32\lib\site-packages\
from serial.serialwin32 import *
File "C:\Python32\lib\site-packages\
e>
from serial import win32
ImportError: cannot import name win32
Setup.py:
from cx_Freeze import setup,Executable
includefiles = ['caml.pkl', 'seql.pkl']
includes = ['DataBase', 'serial.win32']
excludes = ['Tkinter']
packages = []
setup(
name = 'Setup',
version = '0.1',
description = 'Snapper configuration utility',
author = 'LST',
author_email = 'info#-.com',
options = {'build_exe': {'excludes':excludes,'packages':packages,'include_files':includefiles}},
executables = [Executable('snapper.py')]
)
Any idea where to go from here?
Thanks in advance
I tried to do a blind import:
if False:
import serial.win32
no luck...
Maybe i am looking at this the wrong way....
Okay, problem solved.
You need to use packages to force cx_Freeze to include serial.win32 (not "include")
Following line works:
packages = ['serial.win32']
Memo to my self and others: Be sure to check the dist folder for actually included packages. I have no idea why all packages didn't get included by cx_Freeze in the first place, but this works for me.
If you can use a different tool to freeze your program, PyInstaller says it supports PySerial.

Resources