cx_Freeze error module SSL not available Python 3.7 Windows 10 - windows-10

I made a program in Python 3 to make a board of a Bot to Crypto currency. The program works fine without error but with cx_Freeze I have an error on a query with coinmarketcap with the error that the SSL module is missing.
import sys
from cx_Freeze import setup, Executable
import os
import requests.certs
packages = ["tkinter", "requests", "idna", "queue", "coinmarketcap", "requests_cache", "PIL", "urllib3", "OpenSSL", "ssl", "arrow", "tempfile", "json", "locale", "C:\\Users\\cavaud\\Desktop\\botTKinker\\config", "time", "sys", "MySQLdb", "urllib.request"]
includeFile = [requests.certs.where(), "cacert.pem", "ico24x24.ico" , "bas.png", "haut.png", "egal.png", "level.png", "logoBotV2H2.png", "orderNOK.gif", "orderOK.gif", "C:\\Users\\cavaud\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs\\tcl86t.dll", "C:\\Users\\cavaud\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs\\tk86t.dll"]
path = sys.path
os.environ['TCL_LIBRARY'] = "C:\\Users\\cavaud\\AppData\\Local\\Programs\\Python\\Python37-32\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\cavaud\\AppData\\Local\\Programs\\Python\\Python37-32\\tcl\\tk8.6"
os.environ['REQUESTS_CA_BUNDLE'] = "cacert.pem"
base = None
if sys.platform == "win32":
base = "Win32GUI"
options = { "path": path,
"includes": includeModule,
"include_files": includeFile,
"packages" : packages,
"silent": False
}
options["include_msvcr"] = True
cible_1 = Executable(
script="botTK.py",
base=base,
icon="ico24x24.ico"
)
setup(
name="BotTK",
version="1.00",
description="BOT TK",
author="moi",
options={"build_exe": options},
executables=[cible_1]
)
Thank you

Try to modify your setup.py script as follows:
includeFile = [(requests.certs.where(), "cacert.pem"), "ico24x24.ico" , "bas.png", "haut.png", "egal.png", "level.png", "logoBotV2H2.png", "orderNOK.gif", "orderOK.gif", "C:\\Users\\cavaud\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs\\tcl86t.dll", "C:\\Users\\cavaud\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs\\tk86t.dll"]
(please note the parentheses around the first two entries!), and
os.environ['REQUESTS_CA_BUNDLE'] = os.path.join(os.getcwd(), "cacert.pem")
See Requests library: missing SSL handshake certificates file after cx_Freeze

Related

AWS Lambda Python 3.7 Web Scraping - "Could not get version for Chrome with this command: google-chrome --version"

Via an S3 bucket, I've uploaded a lambda function along with its dependencies as a ZIP file. The lambda function is a web scraper with the following initial code to get the scraper started:
import json
import os
import pymysql
import boto3
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.support import expected_conditions as EC
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--window-size=1280x1696')
chrome_options.add_argument('--user-data-dir=/tmp/user-data')
chrome_options.add_argument('--hide-scrollbars')
chrome_options.add_argument('--enable-logging')
chrome_options.add_argument('--log-level=0')
chrome_options.add_argument('--v=99')
chrome_options.add_argument('--single-process')
chrome_options.add_argument('--data-path=/tmp/data-path')
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--homedir=/tmp')
chrome_options.add_argument('--disk-cache-dir=/tmp/cache-dir')
chrome_options.binary_location = os.getcwd() + "/bin/headless-chromium"
browser = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=chrome_options)
When I try to test the lambda function, I get the following error in the console:
{
"errorMessage": "Could not get version for Chrome with this command: google-chrome --version",
"errorType": "ValueError",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 67, in lambda_handler\n browser = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=chrome_options)\n",
" File \"/var/task/webdriver_manager/chrome.py\", line 24, in install\n driver_path = self.download_driver(self.driver)\n",
" File \"/var/task/webdriver_manager/manager.py\", line 32, in download_driver\n driver_version, is_latest = self.__get_version_to_download(driver)\n",
" File \"/var/task/webdriver_manager/manager.py\", line 23, in __get_version_to_download\n return self.__get_latest_driver_version(driver), True\n",
" File \"/var/task/webdriver_manager/manager.py\", line 17, in __get_latest_driver_version\n return driver.get_latest_release_version()\n",
" File \"/var/task/webdriver_manager/driver.py\", line 54, in get_latest_release_version\n self._latest_release_url + '_' + chrome_version())\n",
" File \"/var/task/webdriver_manager/utils.py\", line 98, in chrome_version\n .format(cmd)\n"
]
}
In response, I tried editing the utils.py file in the webdriver_manager dependency folder, by using other commands like 'chrome --version' and 'chromium-browser --version' instead of 'google-chrome --version' under the function definition of 'chrome_version()', but got the similar error of not being able to the get the chrome version from the new command:
def chrome_version():
pattern = r'\d+\.\d+\.\d+'
cmd_mapping = {
OSType.LINUX: 'google-chrome --version',
OSType.MAC: r'/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version',
OSType.WIN: r'reg query "HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version'
}
cmd = cmd_mapping[os_name()]
stdout = os.popen(cmd).read()
version = re.search(pattern, stdout)
if not version:
raise ValueError(
'Could not get version for Chrome with this command: {}'
.format(cmd)
)
return version.group(0)
Can anyone tell me what command I should be using instead of 'google-chrome --version'?
By default, Google Chrome does not exists on the container that runs our lambda functions.
I'm implementing similar solutions but with JavaScript and the way I solve is by using a micro-browser (Chromium) using the following packages:
"chrome-aws-lambda": "^1.19.0",
"puppeteer-core": "^1.19.0"
For Python, here is a tutorial that might help in your situation.
https://robertorocha.info/setting-up-a-selenium-web-scraper-on-aws-lambda-with-python/

Linking installed library WiringPi to Adafruit's scons script build

I recently used Neopixel's library provided by Adafruit's (here) on a Raspberry Pi 3 with Raspbian Jessie with Pixel.
Adafruit used a Scons script file to manage build:
SConscript File:
Import(['clean_envs'])
tools_env = clean_envs['userspace'].Clone()
# Build Library
lib_srcs = Split('''
mailbox.c
ws2811.c
pwm.c
dma.c
rpihw.c
''')
version_hdr = tools_env.Version('version')
ws2811_lib = tools_env.Library('libws2811', lib_srcs)
tools_env['LIBS'].append(ws2811_lib)
# Shared library (if required)
ws2811_slib = tools_env.SharedLibrary('libws2811', lib_srcs)
# Test Program
srcs = Split('''
main.c
''')
objs = []
for src in srcs:
objs.append(tools_env.Object(src))
test = tools_env.Program('test', objs + tools_env['LIBS'])
Default([test, ws2811_lib])
SConstruct File:
import os
opts = Variables()
opts.Add(BoolVariable('V',
'Verbose build',
False))
platforms = [
[
'userspace', # Target Name
[ 'linux', 'version' ], # Scons tool (linux, avr, etc.)
{ # Special environment setup
'CPPPATH' : [
],
'LINKFLAGS' : [
],
},
],
]
clean_envs = {}
for platform, tool, flags in platforms:
env = Environment(
options = opts,
tools = tool,
toolpath = ['.'],
ENV = {'PATH' : os.environ['PATH']},
LIBS = [],
)
env.MergeFlags(flags)
clean_envs[platform] = env
Help(opts.GenerateHelpText(clean_envs))
Export(['clean_envs'])
SConscript('SConscript');
My problem is that I currently use gcc, to link wiringPi library I'm using "-lwiringPi" option during compiling.
How can I add the link to wiringPi inside my scons script file?
Thank you very much for your help, and have a good day !
Hugo.

CX_Freeze : Import error : _ufuncs_cxx

I am currently using Python 3.4 on my windows 10 64x and trying to freeze my application using CX_Freeze. Unfortunetly, I get an error message : "Import error : No module named scipy.special._ufuncs_cxx".
Here is my setup.py :
# -*- coding: Latin-1 -*-
import sys
import scipy
from cx_Freeze import setup, Executable
import PyQt4
packages=['PyQt4.QtCore', 'PyQt4.QtGui', 'sys', 'socket', 'pprint', 'pandas', 'datetime', 'json','numpy', 'scipy']
include_files=['C:/Users/sadid/OneDrive/Documents/Visual Studio 2015/Projects/db/img/lib-ico.ico',
'C:/Users/sadid/OneDrive/Documents/Visual Studio 2015/Projects/Lib/db/img']
if sys.platform == 'win32':
base = 'Win32GUI'
exe = Executable(
script='C:/Users/sadid/OneDrive/Documents/Visual Studio 2015/Projects/Lib/Lib/main.py',
initScript = None,
base=base,
targetName='Lib.exe',
copyDependentFiles = True,
compress = True,
icon='C:/Users/sadid/OneDrive/Documents/Visual Studio 2015/Projects/LibAppCustomer/LibAppCustomer/db/img/lib-ico.ico'
)
setup(
name ='LibApplication',
version = '1.0.0',
description = 'Pricing\'s Application',
author = 'DIKSA',
executables = [exe],
options = {
"build.exe": {
"packages": packages,
'include_files': include_files,
'includes' : ['scipy.special._ufuncs_cxx']
}
}
)
Any help please guys thx
This issue is based on how scipy loads itself and there is a plan in place to have cx_Freeze handle these and other such issues -- but it is still in progress. The comments in this issue, however, can help you workaround the issue for now:
https://bitbucket.org/anthony_tuininga/cx_freeze/issues/43/import-errors-when-using-cx_freeze-with

cx_freeze DLL load failed with Scipy

When using cx_freeze with my application I get the following error when runnig the executable:
The setup.py file is:
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"includes": ['numpy', 'networkx', 'pandas', 'xlwt', 'matplotlib', 'xlsxwriter', 'numba', 'scipy.sparse.linalg', 'scipy.sparse.csgraph._validation'],
"packages": ['pkg_resources'],
'excludes' : [],
"include_files": [('C:\\Anaconda3\\Lib\\site-packages\\scipy\\special\\_ufuncs.pyd','_ufuncs.pyd'), ('C:\\Anaconda3\Lib\\site-packages\\scipy\\sparse\\linalg\\isolve\\_iterative.pyd', '_iterative.pyd')]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "GridCal",
version = "0.1",
description = "GridCal",
options = {"build_exe": build_exe_options},
executables = [Executable("main_gui.py", base=base)])
The scipy.sparse.linalg.isolve._iterative.pyd libary is there, so I don't know what the problem is.

Using cx_freeze in PyQt5, can't find PyQt5

I want to build a standalone binary file for windowz(xp, 7, ...) from my python3(+ PyQt5) script and I inevitably use cx_freeze because other freezing apps do not work with python3 (like py2exe, pyinstaller).
I read the cx_freeze docs and lots of stackoverflow asks ans use this config for setup.py‍‍‍ file :
import sys
from cx_Freeze import setup, Executable
path_platforms = ( "C:\Python33\Lib\site-packages\PyQt5\plugins\platforms\qwindows.dll", "platforms\qwindows.dll" )
includes = ["atexit","PyQt5.QtCore","PyQt5.QtGui", "PyQt5.QtWidgets"]
includefiles = [path_platforms]
excludes = [
'_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter'
]
packages = ["os"]
path = []
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"includes": includes,
"include_files": includefiles,
"excludes": excludes,
"packages": packages,
"path": path
}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
exe = None
if sys.platform == "win32":
exe = Executable(
script="D:\\imi\\aptanaWorKPCworkspace\\azhtel\\tel.py",
initScript = None,
base="Win32GUI",
targetDir = r"dist",
targetName="tel.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup(
name = "telll",
version = "0.1",
author = 'me',
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [exe]
)
run with:
python D:\imi\aptanaWorKPCworkspace\azhtel\setup.py build
This is my library that I used:
from PyQt5 import QtGui, QtCore, QtWidgets
import sys
from telGui import Ui_MainWindow
import mysql
import mysql.connector
from mysql.connector import errorcode
and this is my files in workspace:
But this error happened (or another kind of errors).
Why this happened and what config for setup.py is good for pyqt5 app ??
Thanks.
Python3.3, PyQt5, Mysqlconnector.
I solved this problem with find another directory near the dist directory called build and all library files are in there, i delete targetDir = r"dist" part of setup.py and everythings is alright !
Try pyinstaller. It's much better than cxfreeze.

Resources