I wanted to run some code in IronPython using c#. In this code I needed to use numpy. So I tried to install it using the command below:
ipy -X:Frames -m pip install -U numpy
Unfortunately, I get an error and a return message telling me it was a unsuccessful installation. The error message is bellow:
Using cached https://files.pythonhosted.org/packages/3a/20/c81632328b1a4e1db65f45c0a1350a9c5341fd4bbb8ea66cdd98da56fe2e/numpy-1.15.0.zip
Installing collected packages: numpy
Running setup.py install for numpy ... error
Complete output from command "C:\Program Files\IronPython 2.7\ipy.exe" -u -c "import setuptools, tokenize;__file__='c:\\users\\mbhamida\\appdata\\local\\temp\\pip-build-t61kxu\\numpy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\mbhamida\appdata\local\temp\pip-y91bz0-record\install-record.txt --single-version-externally-managed --compile:
Running from numpy source directory.
Note: if you need reliable uninstall behavior, then install
with pip instead of using `setup.py install`:
- `pip install .` (from a git repo or downloaded source
release)
- `pip install numpy` (last NumPy release on PyPi)
C:\Program Files\IronPython 2.7\Lib\distutils\dist.py:1: UserWarning: Unknown distribution option: 'python_requires'
"""distutils.dist
blas_opt_info:
blas_mkl_info:
customize MSVCCompiler
libraries mkl_rt not found in ['C:\\Program Files\\IronPython 2.7\\lib']
NOT AVAILABLE
blis_info:
customize MSVCCompiler
libraries blis not found in ['C:\\Program Files\\IronPython 2.7\\lib']
NOT AVAILABLE
openblas_info:
customize MSVCCompiler
customize MSVCCompiler
libraries openblas not found in ['C:\\Program Files\\IronPython 2.7\\lib']
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\setup.py", line 410, in <module>
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\numpy\distutils\core.py", line 135, in setup
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\numpy\distutils\system_info.py", line 625, in get_info
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\numpy\distutils\system_info.py", line 433, in get_info
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\numpy\distutils\system_info.py", line 625, in get_info
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\numpy\distutils\system_info.py", line 1758, in calc_info
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\numpy\distutils\fcompiler\__init__.py", line 61, in <module>
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\setup.py", line 402, in setup_package
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\setup.py", line 167, in configuration
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\numpy\distutils\misc_util.py", line 1032, in add_subpackage
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\numpy\distutils\misc_util.py", line 998, in get_subpackage
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\numpy\distutils\misc_util.py", line 940, in _get_configuration_from_setup_py
File "numpy\setup.py", line 10, in configuration
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\numpy\distutils\misc_util.py", line 1032, in add_subpackage
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\numpy\distutils\misc_util.py", line 998, in get_subpackage
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\numpy\distutils\misc_util.py", line 940, in _get_configuration_from_setup_py
File "numpy\core\setup.py", line 832, in configuration
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\numpy\distutils\system_info.py", line 433, in get_info
File "c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\numpy\distutils\system_info.py", line 1621, in calc_info
TypeError: a new-style class can't have only classic bases
----------------------------------------
Command ""C:\Program Files\IronPython 2.7\ipy.exe" -u -c "import setuptools, tokenize;__file__='c:\\users\\mbhamida\\appdata\\local\\temp\\pip-build-t61kxu\\numpy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\mbhamida\appdata\local\temp\pip-y91bz0-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\mbhamida\appdata\local\temp\pip-build-t61kxu\numpy\
I searched a lot about a solution, but I guess it is a very common problem.
Ps: I face the same problem with many other packages.
What can be the solution?
Python is first and foremost a language and has a default implementation in C: CPython. IronPython is another implementation of the language, based on .NET. As such, it implements the default core language and most of the standard library.
Some Python packages available through PIP are pure Python and rely on elements supported by IronPython. Some other modules are, however, specific to the implementation. In particular, numpy uses native C code, which is supported by CPython but not by IronPython. More info on the IronPython issue tracker: https://github.com/IronLanguages/ironpython2/issues/
For it to work, numpy would have to offer compatibility with .NET. I have seen a .NET refactor of numpy, but never got it working.
A solution for your problem? Avoid mixing numpy and .NET. If you find a way to make it work, though, I'm interested.
[Edit:] You might want to have a look at this answer on how to install numpy: https://stackoverflow.com/a/51900761/6690989
Related
I am trying to install several packages to use it in a C# app via IronPython. However I get the following error when I run ipy -X:Frames -m pip install package_name from the windows console:
Exception:
Traceback (most recent call last):
File "c:\Program Files (x86)\IronPython 2.7\Lib\site-packages\pip\basecommand.py", line 209, in main
status = self.run(options, args)
File "c:\Program Files (x86)\IronPython 2.7\Lib\site-packages\pip\commands\install.py", line 299, in run
requirement_set.prepare_files(finder)
File "c:\Program Files (x86)\IronPython 2.7\Lib\site-packages\pip\req\req_set.py", line 356, in prepare_files
discovered_reqs.extend(self._prepare_file(
File "c:\Program Files (x86)\IronPython 2.7\Lib\contextlib.py", line 35, in __exit__
self.gen.throw(type, value, traceback)
File "c:\Program Files (x86)\IronPython 2.7\Lib\site-packages\pip\utils\logging.py", line 36, in indent_log
yield
ValueError: too many values to unpack
Update: Before the exception I see two warnings. Maybe they have to do with the problem.
C:\Program Files (x86)\IronPython 2.7\Lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:1: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
from __future__ import absolute_import
C:\Program Files (x86)\IronPython 2.7\Lib\site-packages\pip\_vendor\requests\packages\urllib3\connection.py:1: SubjectAltNameWarning: Certificate for pypi.python.org has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/shazow/urllib3/issues/497 for details.)
from __future__ import absolute_import
I can install NLTK via pip in my separate python installation. I tried to reference these packages via sys.path.append() but it doesn't work either. However, I don't think it would be a good solution anyway.
I'm trying to install the llvmlite in my windows 10, so i'm following the step-by-step from the documentation:
You must have Visual Studio 2013 or later (the free “Express” edition is ok) in order to compile LLVM and llvmlite.
In addition, you must have cmake installed, and LLVM should have been built using cmake, in Release mode. Be
careful to use the right bitness (32- or 64-bit) for your Python installation.
So, i already have everything, and when i try to install with the command python setup.py build, the following error occurs:
Trying generator 'Visual Studio 12 2013'
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_CXX_COMPILER could be found.
-- Configuring incomplete, errors occurred!
See also "C:/Users/G1745 IRON/AppData/Local/Temp/tmpvzyvoz/CMakeFiles/CMakeOutput.log".
See also "C:/Users/G1745 IRON/AppData/Local/Temp/tmpvzyvoz/CMakeFiles/CMakeError.log".
Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\llvmlite\ffi\build.py", line 152, in <module>
main()
File "C:\Python27\Lib\site-packages\llvmlite\ffi\build.py", line 140, in main
main_win32()
File "C:\Python27\Lib\site-packages\llvmlite\ffi\build.py", line 74, in main_win32
generator = find_win32_generator()
File "C:\Python27\Lib\site-packages\llvmlite\ffi\build.py", line 70, in find_win32_generator
raise RuntimeError("No compatible cmake generator installed on this machine")
RuntimeError: No compatible cmake generator installed on this machine
error: command 'C:\\Python27\\python.exe' failed with exit status 1
Searching a lot, i found that i should use the following command cmake -G "Visual Studio 14 2015", but that's returning:
CMake Error: The source directory "C:/Python27/Lib/site-packages/llvmlite" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
I help would be very much appreciated.
i use windows 10, python 2 & python 3 and regularly use the link provided by #roganjosh to download & install pre-compiled binaries. i have just repeated this for a clean install, and yes, it works perfectly for llvmlite. for numba too.
I've been using IronPython to use functions in a C# .dll class library. I have also been using another set of packages called Psychopy. However, IronPython does not recognize Pyschopy packages. I tried placing a .pth file that said the following in IronPython's site-packages folder: C:/Program Files (x86)/PsychoPy2/Lib/site-packages/PsychoPy-1.80.03-py2.7.egg
I then changed the sys.prefix, sys.exec_prefix variables in site.py to "C:/Program Files (x86)/IronPython 2.7". Then, I went to the command line and in the ironpython shell, I tried to import psychopy. I received the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in '<'module'>'
File "C:\Program Files (x86)\PsychoPy2\Lib\site-packages\PsychoPy-1.80.03-py2.7.egg\psychopy\__init__.py", line 33, in '<'module'>'"
File "C:\Program Files (x86)\PsychoPy2\Lib\site-packages\PsychoPy-1.80.03-py2.7.egg\psychopy\preferences\__init__.py", line 5, in '<'module'>'
File "C:\Program Files (x86)\PsychoPy2\Lib\site-packages\PsychoPy-1.80.03-py2.7.egg\psychopy\preferences\preferences.py", line 186, in '<'module'>'
File "C:\Program Files (x86)\PsychoPy2\Lib\site-packages\PsychoPy-1.80.03-py2.7.egg\psychopy\preferences\preferences.py", line 32, in __init__
File "C:\Program Files (x86)\PsychoPy2\Lib\site-packages\PsychoPy-1.80.03-py2.7.egg\psychopy\preferences\preferences.py", line 95, in getPaths
File "C:\Program Files (x86)\IronPython 2.7\Lib\os.py", line 423, in __getitem__
KeyError: HOME
I was wondering if anyone know how to install thrid party packages in Ironpython.
I'm guessing that you can fix this by adding HOME as an environment variable (System properties>Advanced) and pointing it to your home folder.
I'm not sure why that step is needed for IronPython but not for regular C python - I guess C Python creates it if it isn't found?
I also don't know what else will go wrong in PsychoPy; I've never used IronPython
Jon
I am trying to bundle the application with mono 3.2.3 to a stand-alone executable. To do so, I am following this guideline. After declarating variables:
mono_version="3.2.3"
export MONO=/cygdrive/c/progra~2/Mono-$mono_version
machineconfig=$PROGRAMFILES\\Mono-$mono_version\\etc\\mono\\4.5\\machine.config
export PATH=$PATH:$MONO/bin
export PKG_CONFIG_PATH=$MONO/lib/pkgconfig
export CC="i686-pc-mingw32-gcc -U _WIN32"
mkbundle --deps command cannot localize referenced assemblies:
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'gtk-sharp' or
one of its dependencies. The system cannot find the file specified.
File name: 'gtk-sharp'
performing exactly the same operation with mono 2.10.9:
mono_version="2.10.9"
export MONO=/cygdrive/c/progra~2/Mono-$mono_version
machineconfig=$PROGRAMFILES\\Mono-$mono_version\\etc\\mono\\4.0\\machine.config
export PATH=$PATH:$MONO/bin
export PKG_CONFIG_PATH=$MONO/lib/pkgconfig
export CC="i686-pc-mingw32-gcc -U _WIN32"
mkbundle --deps --machine-config "$machineconfig" -c UI.exe
gives positive result:
OS is: Windows
WARNING:
Check that the machine.config file you are bundling
doesn't contain sensitive information specific to this machine.
Sources: 3 Auto-dependencies: True
embedding: C:\users\piotr\desktop\authoringtool\UI\bin\debug\UI.exe
config from: C:\users\piotr\desktop\authoringtool\UI\bin\debug\UI.exe.config
embedding: C:\PROGRA~2\MONO-2~1.9\lib\mono\gac\gtk-sharp\2.12.0.0__35e10195dab3c99f\gtk-sharp.dll
embedding: C:\PROGRA~2\MONO-2~1.9\lib\mono\gac\glib-sharp\2.12.0.0__35e10195dab3c99f\glib-sharp.dll
.
.
.
embedding: C:\PROGRA~2\MONO-2~1.9\lib\mono\4.0\Mono.Posix.dll
Machine config from: C:\Program Files (x86)\Mono-2.10.9\etc\mono\4.0\machine.config
Compiling:
as -o temp.o temp.s
Does anyone know the reason of such behavior? I'm using 64-bit version of windows 7 and the Cygwin I found on the official website. The code was compiled and tested on Xamarin Studio 4.2 and Visual Studio 2010.
Howto for mkbundle on cygwin + mingw
Tested with mono 4.0.3
In mono 4.0.3, mkbundle works but it can be tricky to make it work.
First, check your setup:
Install Mono/GTK# in a path that doesn't contains spaces (ie not Program Files then)
Setup a MinGw/Cygwin working compile chain (as the one for
compiling mono on windows).
Define the mandatory environment variables for mkbundle:
mingw compiler location should be in the Windows PATH (used by cmd)
pkg-config should also be in the Windows PATH
Use the following cygwin script (it can be adapted to run on cmd)
# M_PREFIX refers to Mono installation
# For more information, search for prefix installation in Mono documentation
M_PREFIX='/cygdrive/c/Mono'
export DYLD_FALLBACK_LIBRARY_PATH=${M_PREFIX}/lib:${DYLD_FALLBACK_LIBRARY_PATH}
export LD_LIBRARY_PATH=${M_PREFIX}/lib:${M_PREFIX}/lib/mono/4.5:${LD_LIBRARY_PATH}
export C_INCLUDE_PATH=${M_PREFIX}/include:${C_INCLUDE_PATH}
export ACLOCAL_PATH=${M_PREFIX}/share/aclocal:${ACLOCAL_PATH}
export PKG_CONFIG_PATH=${M_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}
# Here we added the system32 to make cmd available to mkbundle
# /usr/bin is the default location for mingw
export PATH=${M_PREFIX}/bin:/cygdrive/c/Windows/system32:/usr/bin:${PATH}
export CC="i686-pc-mingw32-gcc -U _WIN32"
Then you can run:
mkbundle --deps --keeptemp my.exe my.dll -o bundled.exe
Notes:
- Copy mono-2.0.dll in the application directory as it should be distributed along the bundled exe
cp ${M_PREFIX}/bin/mono-2.0.dll .
if -z is used, zlib1.dll should be copied as well. (note that gcc invocation change also). You may need more dll depending on your usage of framework features (not exhaustive list : libglib*.dll, libgmodule*.dll, libgthread*.dll, iconv.dll, intl.dll)
-c is used to generate only stub.
You must specify all exe and dll that are needed for the bundle.
--keeptemp will keep temp.c and temp.s which could come in handy if mkbundle fail on gcc invocation.
If you want to invoke gcc by hand (and it may be needed):
i686-pc-mingw32-gcc -U _WIN32 -g -o output.exe -Wall temp.c $(pkg-config --cflags --libs mono-2) temp.o
For Console Applications
To make console application work you must remove -mwindows from the gcc command. To do that, you must invoke pkg-config --cflags --libs mono-2 and remove the -mwindows.
You should obtain something like that afterwards:
i686-pc-mingw32-gcc -g -o output.exe -Wall temp.c -mms-bitfields -IC:/Mono/include/mono-2.0 -mms-bitfields -LC:/Mono/lib -lmono-2.0 -lws2_32 -lpsapi -lole32 -lwinmm -loleaut32 -l advapi32 -lversion temp.s
Anyone can improve mkbundle
mkbundle is an open sourced C# console application (on mono github)
so it can be easily modified and recompiled depending on your needs.
Reading the code could also be helpful to understand how it works underneath.
cmd usage as the different commands used by mkbundle are hard coded so it would benefit from some parametrization enhancement.
Im trying to create an executable from a console application.
I have installed mono,cygwin (mingw-gcc, mingw-zlib1, mingw-zlib-devel, pkg-config) and I have added the following lines to my .bashrc file
export PKG_CONFIG_PATH=/cygdrive/c/progra~1/Mono-3.2.3/lib/pkgconfig
export PATH=$PATH:/cygdrive/c/progra~1/Mono-3.2.3/bin
export CC="i686-pc-mingw32-gcc -U _WIN32"
But everytime I try to use mkbundle I receive the following message
Is there a way to make mkbundle work properly on windows.?
(Im using windows 7 x86, mono 3.2.3, the cygwin I found on the official website, xamarin studio 4.2 and net framwork 4)
This problem is still presented in the current mono version under the Windows. This happened because of mono team switched default GC to SGEN. So when you try to use mkbundle as you can see in your error mkbundle utility try to find mono-2 library but this lib didn't included in setup and you have a fail. To solve this you should configure mkbundle to use libmonosgen-2.0 instead of mono-2. Let's try to do this.
The key moment is setting this variable:
export PKG_CONFIG_PATH=/cygdrive/c/progra~1/Mono-3.2.3/lib/pkgconfig
If you go to this directory you will see a lot of *.pc files (package config). This files are responsible for configuration of linking libraries during bundling process. For some reasons mono team hard coded package config file and library to mono-2 (see this line 492). How could we fix it without rebuilding mkbundle? The solution is to use the next bundle script:
# Mono paths
mono_version="3.2.3"
export MONO=/cygdrive/c/progra~2/Mono-$mono_version
machineconfig=$PROGRAMFILES\\Mono-$mono_version\\etc\\mono\\4.5\\machine.config
export PATH=$PATH:$MONO/bin
export PKG_CONFIG_PATH=$MONO/lib/pkgconfig
# Compiller
export CC="i686-pc-mingw32-gcc -U _WIN32"
# Output file name
output_name=Prog.exe
# Produce stub only, do not compile
mkbundle --deps --machine-config "$machineconfig" -c Program.exe
# Produce helper object file. You may see errors at this step but it's a side effect of this method.
mkbundle --deps --machine-config "$machineconfig" -oo temp.o Program.exe
# Compile. Pay attention where I use monosgen-2
i686-pc-mingw32-gcc -U _WIN32 -g -o "$output_name" -Wall temp.c `pkg-config --cflags --libs monosgen-2` temp.o
# Copy libmonosgen-2.dll
cp $MONO/bin/libmonosgen-2.0.dll .
# Run
./$output_name
I had the same problem some time ago and made a script for cygwin. You can try it, would be interesting whether it still works:
mkbunde cygwin script
There are explanations in the script how to setup the environment.
Howto for mkbundle on cygwin + mingw
Here you can find an updated howto make mkbundle work on Windows
First, check your setup:
Install Mono/GTK# in a path that doesn't contains spaces (ie not Program Files then)
Setup a MinGw/Cygwin working compile chain (as the one for
compiling mono on windows).
Define the mandatory environment variables for mkbundle:
mingw compiler location should be in the Windows PATH (used by cmd)
pkg-config should also be in the Windows PATH
Use a cygwin script to defined mono and mingw required variables.
Then you can run:
mkbundle --deps --keeptemp my.exe my.dll -o bundled.exe
Notes:
Copy mono-2.0.dll in the application directory as it should be distributed along the bundled exe
You must specify all exe and dll that are needed for the bundle.
--keeptemp will keep temp.c and temp.s which could come in handy if mkbundle fail on gcc invocation.
If you want to invoke gcc by hand (and it may be needed):
i686-pc-mingw32-gcc -U _WIN32 -g -o output.exe -Wall temp.c $(pkg-config --cflags --libs mono-2) temp.o
Anyone can improve mkbundle
mkbundle is an open sourced C# console application (on mono github)
so it can be easily modified and recompiled depending on your needs.
Reading the code could also be helpful to understand how it works underneath.