Include python extension module written in C - Error importing MAXREPEAT - python

I have written a Python extension module in C. In order to compile the C code to create a proper .py, I tried to use gcc and Anaconda, but for some reason there are a number of functions in my code that are not available in the python27.lib provided in Anaconda. If I use another python27.lib file, I get far more error.
So, instead I tried writing a python script that creates the extension. The following code was included in the python script to generate the c extension:
from distutils.core import setup, Extension
# the c extension module
extension_mod = Extension("chr", ["chr.c"])
setup(name = "chr", ext_modules=[extension_mod])
Now, when I try to run this script in cmd, using the following command, I get the error mentioned below. It seems like the problem is some module named MAXREPEAT, but I am sure that if I figure out how to add that one, another will pop-up. Am I doing something fundamentally wrong?
I tried doing something similar with a simple helloworld.c extension, and had similar issues.
python testchr.py build_ext --include
C:\Users\ininaa\Documents\Ladi\python>python testchr.py build_ext --include
Traceback (most recent call last):
File "C:\Python27_win32\Lib\site.py", line 548, in <module>
main()
File "C:\Python27_win32\Lib\site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "C:\Python27_win32\Lib\site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File "C:\Python27_win32\Lib\site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "C:\Python27_win32\Lib\site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "C:\Python27_win32\Lib\sysconfig.py", line 516, in get_config_var
return get_config_vars().get(name)
File "C:\Python27_win32\Lib\sysconfig.py", line 449, in get_config_vars
import re
File "C:\Python27_win32\Lib\re.py", line 105, in <module>
import sre_compile
File "C:\Python27_win32\Lib\sre_compile.py", line 14, in <module>
import sre_parse
File "C:\Python27_win32\Lib\sre_parse.py", line 17, in <module>
from sre_constants import *
File "C:\Python27_win32\Lib\sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT

Related

Creating jupyter notebook with Python code

I am creating a jupyter notebook programatically with Python. Using the nbformat library.
Once I create the file:
fname = f'{filename}.ipynb'
with open(fname, 'w') as notebook:
nbf.write(nb, notebook)
I open the file with Jupyter Lab and get the following error in the terminal console:
Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
File "/Users/sota/anaconda3/lib/python3.8/site.py", line 580, in <module>
main()
File "/Users/sota/anaconda3/lib/python3.8/site.py", line 567, in main
known_paths = addsitepackages(known_paths)
File "/Users/sota/anaconda3/lib/python3.8/site.py", line 350, in addsitepackages
addsitedir(sitedir, known_paths)
File "/Users/sota/anaconda3/lib/python3.8/site.py", line 208, in addsitedir
addpackage(sitedir, name, known_paths)
File "/Users/sota/anaconda3/lib/python3.8/site.py", line 169, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "/Users/sota/anaconda3/lib/python3.8/importlib/util.py", line 14, in <module>
from contextlib import contextmanager
File "/Users/sota/anaconda3/lib/python3.8/contextlib.py", line 5, in <module>
from collections import deque
File "/Users/sota/anaconda3/lib/python3.8/collections/__init__.py", line 24, in <module>
import heapq as _heapq
File "/Users/sota/anaconda3/lib/python3.8/heapq.py", line 581, in <module>
from _heapq import *
KeyboardInterrupt
I have been researching a lot, but I don't get to find the error... some guidance on why this is happening?
PD: the only solution I've found so far is openinig the notebook with vscode and somehow, the notebook gets fixed.
It was actually a very newbie error. I had written the names of the folders with accented characters. Therefore, Jupyter Lab couldn't recognize correctly the files.

ModuleNotFoundError: No module named '_sysconfigdata_m_darwin_darwin'

I'm working on a Rally reporting tool for my team in Python, and I'm trying to package it using cx-freeze. I'm getting a ModuleNotFound error, and I'm wondering if it's because pygal isn't supported by cx-freeze (really hoping this isn't the case because I'd have to rewrite a lot of things)
celinaperalta$ /Users/celinaperalta/Documents/NYLTesting/rally-exports/build/exe.macosx-10.9-x86_64-3.7/RallyGUI ; exit;
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cx_Freeze/initscripts/__startup__.py", line 40, in run
module.run()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cx_Freeze/initscripts/Console.py", line 37, in run
exec(code, {'__name__': '__main__'})
File "RallyGUI.py", line 8, in <module>
File "/Users/celinaperalta/Documents/NYLTesting/rally-exports/build/exe.macosx-10.9-x86_64-3.7/RallyReportTool.py", line 7, in <module>
import pygal
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pygal/__init__.py", line 28, in <module>
import pkg_resources
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 959, in <module>
class Environment:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 963, in Environment
self, search_path=None, platform=get_supported_platform(),
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 190, in get_supported_platform
plat = get_build_platform()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 395, in get_build_platform
plat = get_platform()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sysconfig.py", line 675, in get_platform
get_config_vars(),
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sysconfig.py", line 551, in get_config_vars
_init_posix(_CONFIG_VARS)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sysconfig.py", line 422, in _init_posix
_temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
ModuleNotFoundError: No module named '_sysconfigdata_m_darwin_darwin'
cx_freeze does not include all the packages automatically. When you find ModuleNotFoundError, you need to inlcude the module explicitly in your setup like -
build_exe_options = {'packages': ['_sysconfigdata_m_darwin_darwin']}

Py2exe NotImplementedError: resource_filename() only supported for .egg, not .zip

I am trying to convert a python file into an executable and for that I'm using py2exe. When running the setup.py script to generate the dist folder and the executable file everything goes well.
What goes wrong is that when I'm running the executable the following error message gets displayed:
Traceback (most recent call last):
File "q400.py", line 16, in <module>
File "SUAVE\__init__.pyc", line 12, in <module>
File "SUAVE\Plugins\__init__.pyc", line 11, in <module>
File "SUAVE\Plugins\load_plugin.pyc", line 37, in load_plugin
File "SUAVE\Plugins\pint\__init__.pyc", line 23, in <module>
File "SUAVE\Plugins\pint\unit.pyc", line 423, in __init__
File "pkg_resources\__init__.pyc", line 1171, in resource_filename
File "pkg_resources\__init__.pyc", line 1872, in get_resource_filename
NotImplementedError: resource_filename() only supported for .egg, not .zip
When I check the file unit.pyc at line 423 the code is:
data = pkg_resources.resource_filename(__name__, 'default_en.txt')
And when I check the library.zip in the dist folder there is no default_en.txt file, however, it is present in the site-packages module.
So is it because this file is a txt file that this error shows up?
I tried to force py2exe to import it but with no success.
Also I found a similar question here but the answer can't be applied in my case because I don't have any egg nor zip files implicated in the error (at least in my opinion).
Thank you

when i import arcpy in python idle i get an error

when i type import arcpy i get this error
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from arcpy import da
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\__init__.py", line 21, in <module>
from arcpy.geoprocessing import gp
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\__init__.py", line 14, in <module>
from _base import *
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 578, in <module>
env = GPEnvironments(gp)
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 575, in GPEnvironments
return GPEnvironment(geoprocessor)
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 531, in __init__
self._refresh()
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 533, in _refresh
envset = (set(env for env in self._gp.listEnvironments()))
RuntimeError: NotInitialized
what should i do ?
i need to use arcpy in eclipse also and i can't!
This sometimes happens when there are not enough licenses to go around, or if your organization has disabled automated library downloading as part of their software suite.
Check what version of Python you're using in Eclipse, I know friends who've had to download condas in order to import arcpy without fail.

Python Cmd/Powershell error "Traceback (Most recent call last)"

I was giving a look at the "Learn Python The Hard Way" tutorial and when it told me to try it out by typing Python in Powershell after I installed it just kept giving me this:
PS C:\Users\Zach> python
Traceback (most recent call last):
File "C:\Python27\lib\site.py", line 548, in <module>
main()
File "C:\Python27\lib\site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "C:\Python27\lib\site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File "C:\Python27\lib\site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "C:\Python27\lib\site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "C:\Python27\lib\sysconfig.py", line 516, in get_config_var
return get_config_vars().get(name)
File "C:\Python27\lib\sysconfig.py", line 449, in get_config_vars
import re
File "C:\Python27\lib\re.py", line 105, in <module>
import sre_compile
File "C:\Python27\lib\sre_compile.py", line 14, in <module>
import sre_parse
File "C:\Python27\lib\sre_parse.py", line 17, in <module>
from sre_constants import *
File "C:\Python27\lib\sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
I also tried running through the command prompt and got the same error. I've installed and uninstalled python about 3 times and have done a few reboots to no avail. I am very new to python and I'm confused on what to do here. I would also appreciate any links to other python tutorials.
In this case, from my understanding, you have no modules called "MAXREPEAT" or you(or the installer) have installed it somewhere wrong. A reinstallation or redirecting the path should get it to work.

Categories

Resources