Extension Crashing Python on Import? - python

I have a python extension that is built and installed through distutils (using mingw on windows). However on import of this module the interpreter crashes. Is there anyway to debug and figure out why it crashes?
I did look around online and couldn't find anything specific, or any examples.
EDIT
Sorry i am trying to compile for python 2.5.4 (we need 2.5.4, since we use arcgis geoprocessor library):
http://effbot.org/media/downloads/ftpparse-1.1-20021124.zip
On windows, i define crash as: "Python.exe has encountered a problem and needs to close"
I'll try debugging with GDB
EDIT 2
For what ever reason, doing a
setup.py clean
For the package and doing:
setup.py install
fixed all the problems. :psyduck:

Simply running the following may give you a clue about what call is causing the issue without having to break out a debugger. But if you just get a silent crash you're going to have to put on your detective hat as per Xavier's answer.
strace python -v -c "import faultylib"

I suppose using gdb see http://oldwiki.mingw.org/index.php/gdb

Related

problem in installing mayavi package by pip in windows command prompt

I am a beginner in python. I use windows 10 and IDLE. I have cloned a code from github and there are a bunch of *.py files. when I run the main code in python IDLE there is an error:
ModuleNotFoundError: No module named 'mayavi'
I tried to install mayavi in windows cmd using "pip", but again there is a long error starting with this sentence:
ERROR: Command errored out with exit status 1:
it seems that it is a bit complicated to install mayavi.
is this package installation thing a problem in IDLE? what if I use another IDE?
In fact I am not sure that IDLE is a good choice for coding python or not? In addition I am using python 3.10.1.
I look forward to hearing your advices.
Thanks in advance
Try AnaConda. It will manage the installation of python packages in an organized way.
The main probem was VTK installation. I tried the procedure explained here:
https://www.youtube.com/watch?v=IgvbhyDh8r0&t=222s

Importing python modules works in command line but not in the python 3.8 shell

I'm having a problem with importing modules in python.
When I run my program in the command line it works perfectly fine.
However, when I try to run the same program in the python shell I am prompted with the following error:
ModuleNotFoundError: No module named 'matplotlib'
I already successfully installed matplotlib using 'python -m pip install matplotlib'.
I've read this can happen when you have two different versions of python installed; however, I don't.
I've uninstalled and reinstalled python and I still am having the same issue. I've also uninstalled and reinstalled matplotlib using pip.
I believe my problem is the module paths that python uses to search for imported modules are different between the two.
When I use the 'print(sys.path)' command in the python shell and the command line I get two different outputs.
Any help would be greatly appreciated!!!
The file different system paths between the python shell and the command line
You have two versions of python. I would recommend you to remove all pythons you have and go for anaconda https://www.anaconda.com/distribution/. It will fix your path problems and allow you to create environments with different versions of python. This is the least painful way also for future :) good luck.
I suppose, you have both of the Python versions installed on the same computer.
If that is so, then my answer would be to go inside both Python script folders and install matplotlib on both of them.
I have also faced that issue. My path includes pip of Python 3.7.1 and whenevwer I try to import modules on Python 3.4. It throws an error!
Maybe, you could add both of the Pythons to the path.
I encountered this same problem – python -c "import sklearn" would work just fine, but import sklearn inside a Python program failed. Both my one-liner and program was using the same Python version (version 3.8.10).
I eventually got the program to work by replacing the shebang line (originally #!/usr/bin/python) with #!/bin/env python.
I don't know why this worked exactly (sorry). Presumably some path got reset, and the module loaded from a different location, but it might help someone so I'm posting it here nontheless. (If you know more, feel free to edit this answer.)

How do I install python on a windows machine using a cygwin terminal?

I am trying to install python through cygwin on a windows machine in order to make use of a statistical program that can only be implemented using python in a linux environment.
I have run setup-x86_64.exe and installed all python related cygwin packages in an attempt to install python, but when I open a terminal and type python I just get
$ python
-bash: python: command not found
which is the same for all python commands I try so clearly the installation has not occurred. However, I have found a path to Python-2.7.9 which appears to contain the files required to build python from source.
When I run ./configure it is successful, but when I then input make it fails due to:
File "build/temp.cygwin-1.7.35-x86_64-2.7/libffi/fficonfig.py", line 33, in <module>
ffi_sources += ffi_platforms['X86_WIN64']
KeyError: 'X86_WIN64'
Makefile:488: recipe for target 'sharedmods' failed
make: *** [sharedmods] Error 1
Anyone know why make won't work?
The options in ./configure --help are unfamiliar to me, could any of these options allow for successful installation?
Any ideas would be greatly appreciated, thank you.
Cygwin comes with an installer, called setup.exe or setup-x86_64.exe. Just run it and type python to the search box. Then let it install it for you.
python language interpreter is the basic package you need.
So, this question is 3 years old, but this error still happens with most recent versions of Python 2 (tested with 2.7.13 and 2.7.15)
I was able to get python to build by modifying the following file in the build directory.
--- build/temp.cygwin-2.11.1-x86_64-2.7/libffi/fficonfig.py~ 2018-11-03 14:51:53.290000000 -0400
+++ build/temp.cygwin-2.11.1-x86_64-2.7/libffi/fficonfig.py 2018-11-03 14:53:41.793000000 -0400
## -9,6 +9,7 ##
'X86': ['src/x86/ffi.c', 'src/x86/sysv.S', 'src/x86/win32.S'],
'X86_FREEBSD': ['src/x86/ffi.c', 'src/x86/freebsd.S'],
'X86_WIN32': ['src/x86/ffi.c', 'src/x86/win32.S'],
+ 'X86_WIN64': ['src/x86/ffi.c', 'src/x86/win64.S'],
'SPARC': ['src/sparc/ffi.c', 'src/sparc/v8.S', 'src/sparc/v9.S'],
'ALPHA': ['src/alpha/ffi.c', 'src/alpha/osf.S'],
'IA64': ['src/ia64/ffi.c', 'src/ia64/unix.S'],
The source files, in particular src/x86/win64.S, are present in the source tree. For some reason, ./configure does not seem to be properly adding the option to the dictionary in the fficonfig.py file, which causes the KeyError posted in the question. After making this modification, make and make install completed successfully and I was able to install an alternate version of python in addition to the normal Cygwin package.
I'm not yet sure why this happens, but I thought I would attempt to provide a solution to the question actually asked rather than just telling the asker to install a pre-compiled version using the package manager.
Since building Python from source was said to be a bad idea, I assumed my Cygwin was broken. I attempted to uninstall Cygwin following the instructions on the Cygwin website, but I was unable to remove it due to permission difficulties (I use a university-supplied Windows machine). My last resort was to run the Cygwin installation wizard setup-x86_64.exe and uninstall all packages, then run the wizard once more and select the necessary packages again as if starting from new. Miraculously, installing the required packages from scratch solved the problem and I am now running Python through my Cygwin terminal with no errors.
If you want to run Python on Cygwin, you might need to build it from source.
download the source
unpack it to the directory you could delete later, eg: build
run Cygwin, type: cd /path/to/build
run ./configure --help and read the help about the options you'll need
./configure #options
make

Cleaning out all other installed pythons on OS X

For god's sake I'm going crazy. I'm on OS X mavericks. It seems that I installed a lot of pythons (Anaconda, EDA[something like that] ... ) and I just installed the one from Macports. Then also from Macports I installed a module for python called py-graph-tool. Now when I import this module in python I get this error:
Fatal Python error: PyThreadState_Get: no current thread Abort trap: 6
I found from this question the following: "this error shows up when a module tries to use a python library that is different than the one the interpreter uses, that is, when you mix two different pythons."
So I guess the solution would be to clean all other pythons. So my question is: how to clean all other pythons?
Assuming, you want to use the Anaconda Python for scientific work...do the following:
create a file called .bashrc in your home directory (~)
add the following to it: export PATH=~/anaconda/bin:$PATH
close out all open terminals
Now when you open a fresh terminal, python should bring up the Anaconda Python.

Compiling python-mcrypt in win32?

Um, I'm stumped and really stuck (+_+) here after googling many sites. I'm using mingw32-gcc.exe from Dev-c++ compiler and currently following instructions from this site.
Every time I try here's the result:
C:\Python26>python c:\python26\python-mcrypt-1.1\setup.py install
running install
running build
running build_ext
error: don't know how to compile C/C++ code on platform 'nt' with 'mingw32-gcc.exe' compiler
I've edited the distuils.cfg file in my c:\python26\lib\distuils\distuils.cfg with this parameter
[build]
compiler = mingw32-gcc.exe
Any ideas would be appreciated!
You installed python outside of a compilation environment valids one include cygwin or mingw32 (wich is used by Dev-C++).
To use the command-line mode, you need to find the your compiler installation and find bat script which launch the shell with the proper parameters (This is needed for bith cygwin and mingw).
The alternative is to use Microsft solution for that problem.

Categories