cx_Freeze ModuleNotFoundError: No module named 'codecs' - windows-10

Trying to convert a .py file into a .exe
when trying to run the .exe file in the exe.win32-3.6 folder I get the following error:
C:\Users\Aktan\Desktop\build\exe.win32-3.6>StatisticsCalculator.exe
Fatal Python error: Py_Initialize: unable to load the file system codec
Traceback (most recent call last):
File "C:\Users\Aktan\AppData\Local\Programs\Python\Python36-32\lib\encodings\__init__.py", line 31, in <module>
ModuleNotFoundError: No module named 'codecs'
here is my setup.py code:
import cx_Freeze
import sys
import os
import matplotlib
os.environ['TCL_LIBRARY'] = "C:\\LOCAL_TO_PYTHON\\Python35-32\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\LOCAL_TO_PYTHON\\Python35-32\\tcl\\tcl8.6"
base = None
if sys.platform == 'win32':
base='Win32GUI'
executables = [cx_Freeze.Executable("StatisticsCalculator.py", base=None)]
cx_Freeze.setup(
name="This is a tes",
options = {"build_exe": {"packages":["numpy"]}},
version = "0.01",
description = "Trying to get this to work",
executables = executables
)
and I do not know if it helps, but here are the modules I use in my python program:
import sqlite3
from math import pow, sqrt
from tkinter import Tk, Label, Listbox, END, Button, Message, messagebox
import matplotlib.pyplot as plt
I have python 3.6.3 and I am running Windows 10. Any response would be appreciated.

This is a known issue with cx_Freeze which has been resolved in the source. A new release (5.1.1) will be out shortly to correct that issue!

Related

Importing a .pyd file (created with Cython) inside a .py script

I've created a simple .pyd file from my helloWorld.py script using the sample code from here (https://stackoverflow.com/a/36946412/8729576), and although it does generate the .pyd file (along with a build folder, helloWorld.c file) - it throws an error [ImportError: dynamic module does not define module export function (PyInit_helloWorld)] when I attempt to import the function defined inside the original helloWorld.py called printHW using the normal import syntax of:
from helloWorld import printHW
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_helloWorld)
helloWorld.py
import time
def printHW():
print("Hello World - today's date is %s"%time.strftime('%Y-%m-%d',time.localtime()))
if '__name__' == '__main__':
printHW()
setup.py
try:
from setuptools import setup
from setuptools import Extension
except ImportError:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension("helloWorld",["helloWorld.py"]) ]
for e in ext_modules:
e.cython_directives = {'language_level' : '3'}
setup(
name= 'helloWorld',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules)
and then in the command prompt enter:
python setup.py build_ext --inplace
I've never worked with Cython before so really not sure what I'm doing wrong here and most SO answers are specific and not generic to what I'm trying to understand (with this basic example).
For anyone else that comes across this error - it has to do with the name of your output file. Playing with the name of the output pyd file and the name provided in the setup.py <[Extension("ThisShallBeYourModuleImportName",["helloWorld.py"]) ]> line I was able to fix my issue (thanks to #DavidW). Observe that whatever name you provide to your .py script in the Extensions list is what you will have to import it as, it is case sensitive. Furthermore, to import the compiled .pyd file 'ThisShallBeYourModuleImportName.cp36-win_amd64.pyd' in your python script, all you need is to say import ThisShallBeYourModuleImportName in your python script and it shall import the module, additionally you can remove the .cp36-win_amd64 and it will still be imported successfully. Try building the above setup.py code with the following changes to observe what I've stated:
try:
from setuptools import setup
from setuptools import Extension
except ImportError:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension("jAckSparroW",["helloWorld.py"]) ]
for e in ext_modules:
e.cython_directives = {'language_level' : '3'}
setup(
name= 'WhatEver',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules)
Now open terminal and try
import jacksparrow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'jacksparrow'
import jAckSparroW
>>>

Having problems launching Python3 command. Module 'lib' has no attribute 'core'

This is the log I get when launching a pentesting tool:
Traceback (most recent call last):
File "web-brutator.py", line 7, in <module>
from lib.core.ArgumentsParser import ArgumentsParser
File "/home/pc/web-brutator/lib/core/__init__.py", line 3, in <module>
from .ArgumentsParser import *
File "/home/pc/web-brutator/lib/core/ArgumentsParser.py", line 9, in <module>
import lib.core.Globals as Globals
AttributeError: module 'lib' has no attribute 'core'
The ArgumentsParser.py, line 9:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import os
import re
from lib.core.Config import *
from lib.core.Utils import Utils, LineWrapRawTextHelpFormatter
import lib.core.Globals as Globals
class ArgumentsParser:
python3 --version
Python 3.6.9
Do I need to downgrade any Python module or reinstall any different version? It seems to me some kind of incompatibility.
It is solved using python3.8
I noticed after checking the python version that I have 3.6 in update-alternatives

Why does command prompt import differ from sublime text import?

I have installed with pip several packages (numpy/pandas/blpapi/pyarrow). I work with a Windows 64-bit machine, python3.6 in a sublime environment.
While all packages are shown as correctly imported in the command prompt, some packages are not found by my sublime scripts.
To try and remedy this problem, I used sys.path.insert and changed the names of my scripts, to no avail. The traceback below describes what I'm seeing:
Code in Command Prompt:
>>> import pyarrow
>>> import pandas
>>>
Code in Sublime (better_name.py):
print('Hi')
import numpy
import pandas
Output of better_name.py:
Hi
Traceback (most recent call last):
File "C:\Users\Documents\better_name.py", line 4, in <module>
import pandas
ModuleNotFoundError: No module named 'pandas'
Obtaining the paths in Command Prompt:
>>> import os
>>> import numpy
>>> path = os.path.dirname(numpy.__file__)
>>> print(path)
C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy
>>> import pandas
>>> path = os.path.dirname(pandas.__file__)
>>> print(path)
C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas
Trying to use sys.path.insert :
print('Hi')
import sys
import numpy
import os
sys.path.insert(1, r"C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas")
Output:
C:\Users\Documents>better_name.py
Hi
Traceback (most recent call last):
File "C:\Users\Documents\better_name.py", line 7, in <module>
import pandas
ModuleNotFoundError: No module named 'pandas'
I get the same results whether I change the argument in sys.path.insert to 0.
The issue seems to be that your default version of python points to the 32-bit version - i.e. when you say python your windows system executes the 32 bit version.
One workaround is to specify the full path of your 64 bit version - i.e. launch your script as
C:\PATH\TO\64-BIT-VERSION\PYTHON.EXE your_script.py
from the command line.
The other option is to set your windows environment variables to point to the 64 bit version by default. This link should help

import cv2 doesn't give error on command-Prompt but error on IDLE on Windows 10, Python 3.6.4

I have Installed Python 3 (32bit) on Windows.
I have read this answer, but I can't install cv2 using
pip install opencv_python-3.4.1-cp37-cp37m-win32.whl and it gives error as
opencv_python-3.4.1-cp37-cp37m-win32.whl is not a supported wheel on this platform.
when I tried Python shell, and run the command import cv2 it doesn't give error,
but when I try it as import cv2 in IDLE terminal, then It gives error as
>>> import cv2
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
You could also install opencv in these three easy steps
Type py -m pip install opencv-python
In the same window type python or open IDLE python.
Now type import cv2.
there you go... simple and easy i hope it helps.
1)Download OpenCV from here
2)Extract the zip file to Root drive(mostly 'C'Drive)
3)Goto folder opencv\build\python\2.7\x86 and copy cv2 file to your main Python directory,
in my case Python directory is
C:\Users\Deshmukh Brothers\AppData\Local\Programs\Python\Python36-32\Lib\site-packages
and paste cv2 file there.
4)Run command as python -m idlelib and now it will prompt idle-shell.
5)now it will work as import cv2, it nothing occurred and cursor went to next line then it is successfully installed.

Error while importing scikits.talkbox

I want to use scikits.talkbox, but i get the following error while import scikits.talkbox.
Traceback (most recent call last):
File "/home/seref/Desktop/machine learning codes/MFCC/main.py", line 3, in
from scikits.talkbox.features.mfcc import mfcc
File "/usr/local/lib/python3.5/dist-packages/scikits/talkbox/init.py", line 3, in
from tools import *
ImportError: No module named 'tools'
code sample
import scipy.io.wavfile
from scikits.talkbox.features.mfcc import mfcc
sample_rate, X = scipy.io.wavfile.read("data/test_1.wav")
ceps, mspec, spec = mfcc(X)
I use following code when installing scikits.talkbox
sudo pip3 install scikits.talkbox
Operation system ubuntu 16.10
python interpreter 3.5.2+
If you want MFCCs in Python 3, librosa is probably the better library of your choice.

Resources