I am using python in the MSYS2 environment. The MSYS2 has its own built MINGW python version. Also I can install the official python from the www.python.org.
Here is the problem: If I want to write a python code need to know the python version is MINGW or the official one, how can I do it?
Here are some ways I can image.
Use the "sys.prefix" object. It tells the installation directory. the MSYS2 usually installed in the directory X:\msys2\.... and the official one install in the X:\Python27\ as default. But users may change the installation directory. So this is not a good way.
Use the "sys.version" object can get the version strings show with the compiler name. It shows the MINGW python compiled by GCC, the official one compiled by MSC. But there may have some possibility that there is an other version's python also built by GCC or MSC.
Is there any more elegant way can do this?
Mingw python3 build patched official sysconfig.get_platform() function so it returns "mingw" and can be used for distinguishing from official python builds.
https://github.com/Alexpux/MINGW-packages/blob/abd06ca92d876b9db05dd65f27d71c4ebe2673a9/mingw-w64-python2/0410-MINGW-build-extensions-with-GCC.patch#L54
Another option is to check if GCC is in sys.version.
For example:
import sys
MSYS2 = ("GCC" in sys.version)
print(MSYS2)
> True
This works because the sys.version information has the type of compiler used, and MinGW uses GCC.
python -c "import sys; print(sys.version)"
3.7.4 (default, Aug 15 2019, 18:17:27) [GCC 9.2.0 64 bit (AMD64)]
sys.platform gives msys when in msys-Python.
Related
I'm having trouble installing the regex module for python, and would appreciate any suggestion and help. When I used "pip install" on a Windows system, the following error shows up:
Can't locate pip.pm in #INC <#INC contains: C:/Perl64/site/lib C:/Perl64/lib .) at C:\pathA\pathB\perl\bin/pip line 5.
BEGIN failed--compilation aborted at C:\pathA\pathB\perl\bin/pip line 5.
All I did previously is to install pip, following this post: How do I install Python libraries?
I succeeded in the following steps:
python ez_setup.py
python get-pip.py
but not:
pip install setuptools --upgrade
that is when I got the errors.
I am not familiar with using python on Windows, but I need to do it this time. Seems like there is another pip installed for perl on this computer, but when I check the environment variables, I can't really see anything about pip.
For your information -- the python version is:
2.7.7 |Anaconda 2.0.1 (64-bit)| (default, Jun 11 2014, 10:40:02) [MSC v.1500 64 bit (AMD64)]
Thanks a lot in advance for your help!
Apparently Perl also has a tool named pip. Your PATH variable contains the directory for Perl's pip before the one containing Python's pip. You need to find the location of Python's pip and run it directly using an absolute path or edit the PATH variable for Windows so that the directory containing Python's pip is before the directory containing Perl's pip.
The answers is perfect. Just a addon: you can do that by
Right click on the start button
Go to system> Advanced system settings> Environment Variables
In system variables select path and then click on edit
Reorder paths so that C:\Python27 entry comes before the perl\bin
entry
Save your changes by clicking ok
After successfully compiling Mesos 0.16.0, running the tests fails when checking the PythonFramework. All other tests pass successfully.
Steps I used for building:
./bootstrap
mkdir build
cd build
../configure CXX=g++4.7 CC=gcc-4.7
make
Then, when running the tests;
make check
The results look like this:
[...]
[ RUN ] ExamplesTest.PythonFramework
../../src/tests/script.cpp:78: Failure
Failed
python_framework_test.sh exited with status 1
[ FAILED ] ExamplesTest.PythonFramework (201 ms)
[...]
Environment:
OS X 10.9.1 (Mavericks)
Python 2.7.5 (default, Aug 25 2013, 00:04:04) [GCC 4.2.1 Compatible
Apple LLVM 5.0 (clang-500.0.68)] on darwin
gcc-4.7 (GCC) 4.7.3 Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
How do I build proper Mesos Python bindings that pass the tests within this environment?
Update:
My former answer has mostly become obsolete as of Mesos 0.17.0 due to the fact that this version does fully handle clang compilage (Yay!). So there is no need to compile it using gcc anymore - just go ahead and use Xcode's clang (Xcode commandline utilities).
In case you still get into trouble getting the Python bindings to work, please add a comment or new question here on StackOverflow or post into the Mesos Mailing list.
Mesos version 0.16.0 or lower:
How to fix the Python bindings of Mesos on OS X (10.9).
Install Python 2.7.3 via homebrew
Find out which versions are available
brew versions python
2.7.6 git checkout 3c86d2b /usr/local/Library/Formula/python.rb
2.7.5 git checkout a04b443 /usr/local/Library/Formula/python.rb
2.7.3 git checkout 865f763 /usr/local/Library/Formula/python.rb
2.7.4 git checkout 280581d /usr/local/Library/Formula/python.rb
[...]
Select Python 2.7.3
cd /usr/local/Library/Formula/
git checkout 865f763 /usr/local/Library/Formula/python.rb
brew install python
Make sure you do not force installing a universal build (32 + 64bit) as that would again cause the same issue explained below. The default is 64bit only and that is just fine.
Rebuild Mesos in connection with your custom Python installation
rm -rf build
rm -rf ~/.python-eggs
mkdir build
cd build
../configure CXX=g++-4.7 CC=gcc-4.7 PYTHON=/usr/local/bin/python
make
make check
You should now see a properly functioning test, hence a perfectly fine Mesos Python binding:
[ RUN ] ExamplesTest.PythonFramework
[ OK ] ExamplesTest.PythonFramework (1682 ms)
As asking users to install a custom Python version often is just wrong but in this case appears to be inevitable, let me draft an explanation of the issue. And maybe one of the readers knows a better workaround.
Manually executing that test using the verbosive output setting does help identifying the exact problem.
bin/mesos-tests.sh --gtest_filter="*.PythonFramework" --verbose
Traceback (most recent call last): File
"/Users/till/Documents/Development/github/mesos-master/build/../src/examples/python/test_framework.py",
line 23, in
import mesos File "build/bdist.macosx-10.9-intel/egg/mesos.py", line 26, in File
"build/bdist.macosx-10.9-intel/egg/_mesos.py", line 7, in
File "build/bdist.macosx-10.9-intel/egg/_mesos.py", line 6, in
bootstrap ImportError: dlopen(/Users/till/.python-eggs/mesos-0.16.0-py2.7-macosx-10.9-intel.egg-tmp/_mesos.so,
2): Symbol not found: __ZNSoD0Ev Referenced from:
/Users/till/.python-eggs/mesos-0.16.0-py2.7-macosx-10.9-intel.egg-tmp/_mesos.so
Expected in: flat namespace in
/Users/till/.python-eggs/mesos-0.16.0-py2.7-macosx-10.9-intel.egg-tmp/_mesos.so
The important detail is the fact that the dynamic linkage of that native Python egg failed.
The reasoning is to be found within the distutils build step of this module when building mesos 0.16. The Python distutils derive their build-settings directly from python-config. As your Python was built using clang, the distutils will try to build your native egg using clang as well.
Issues:
Mesos' autoconf phase did not propagate the compiler settings into the distutils build phase. So even though Mesos itself is being built using gcc-4.7 in the above description, the egg is being built using clang. The result is a mishmash of libc++ and stdlibc++ which are not ABI compatible.
that part is being fixed right now, Mesos will use the same compiler in the distutils build phase as well (see MESOS-798 and MESOS-799). Chances are pretty high that when you read this answer, that particular issue was already taken care of.
The default OS X Python distutils do enforce building universal binaries (i386 + x86_64) using parameters that only the gcc-frontend of clang supports. There appears to be no workaround, hence all dynamically linked dependencies of that egg will have to be built for both architectures as well (this appears to be a leftover from OS X 10.6).
Mesos itself is linked statically into that egg, hence it does not have to be built as a universal binary for the egg to build and function on a 64bit platform. It will however fail to execute on a 32bit platform.
As long as Mesos does not support clang compilage (hence being linked against libc++), the only proper workaround seems to be to install a differently compiled Python. A quick and easy solution is using homebrew to install Python 2.7.3. Note: do not install Python 2.7.6 (the current default of homebrew) as that one has issues in connection with its autoconf developer macro (see MESOS-617)
Not sure what I'm doing wrong but when I run pycrypto-2.6.win-amd64-py3.3.exe I get Python 3.3 is required, which I have just installed before I tried to install the crypto. I should also note that I have VS 2013 installed, as I'm reading that I may need to compile the whole thing or something.
Anyway, as an option I have a Fedora installed on a Virtual Box, not sure how use it though but if it is "easier" on Fedora I can try to install it there.
I'm actively searching for a solution but am short on time and would like some help. Thanks.
You probably installed 32bit version of Python - install 64bit version.
pycrypto-2.6.win-amd64-py3.3.exe is binary package which means it's already compiled so you don't need compiler to install it. If compilation were needed you would have to have the same version of Visual C++ which was used to build Python itself; in case of the official Python 3.3 that's Visual C++ 2010 not 2013. See What version of Visual Studio and/or MinGW do I need to build extension modules for a given version of Python? question for more details.
I was wondering if anyone can explain why all of a sudden in Python interactive mode all arrow keys are failing?
When I press up button for example to go through command history I get "^[[A". Same with any other arrow keys.
I have no idea why this happened and it was working before (on OS X Snow Leopard). Does anyone know a way to fix this?
Many thanks,
G
If you are using homebrew, this is an easy fix:
brew uninstall python
brew uninstall readline
brew install readline --universal
brew install python
That fixed it for me (running OS X Mavericks 10.9.5)
I finally got this working. I just had to install readline with easy_install and cursors and backspace started magically working.
sudo /opt/local/bin/easy_install-2.5 readline
You don't say which Python you are using but the symptoms you mention are indeed usually caused by Python not being built with readline support. These days Python on OS X can be built to use either the GNU readline library or the Apple-supplied editline library (AKA libedit). You can use the following two commands to show exactly which Python you are using. If that does not help you figure out what is going on, edit your question to show the output from those commands.
Here's an example that shows a recent MacPorts Python 2.6 on OS X 10.6:
$ python -c 'import sys;print(sys.version);print(sys.executable)'
2.6.5 (r265:79063, Jul 15 2010, 01:53:46)
[GCC 4.2.1 (Apple Inc. build 5659)]
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
$ otool -L $(python -c 'import readline; print(readline.__file__)')
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/readline.so:
/opt/local/lib/libreadline.6.1.dylib (compatibility version 6.0.0, current version 6.1.0)
/opt/local/lib/libncursesw.5.dylib (compatibility version 5.0.0, current version 5.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
The path prefix /opt/local/ is the default location for MacPorts-installed software and the output from otool indicates that this Python's readline module is dynamically linked to the MacPorts-installed GNU readline library.
This behaviour commonly shows when you do not have readline support. If you are using MacPorts, try port install readline, see if it will fix it. You can also see this page for some further explanations.
(Also useful to know: some programs do not use readline even if present on the system. You can force it on them by using rlwrap (port install rlwrap). For example: rlwrap ocaml -init code.ml will start up OCaml, read code.ml, and start REPL with readline support)
The command
brew install readline
worked for me.
We're using this configure script with an option we spotted in the configure help menu:
./configure --with-universal-archs=32-bit --prefix="$HOME/python"
make
make install
But when all the dust is settled and we check out what it gives us:
✔python-3.1.1⤿ file ~/python/bin/python3
python/bin/python3: Mach-O 64-bit executable x86_64
How do we compile it so we're given a 32-bit python? We're looking to use the uno module provided by OpenOffice, which requires 32-bit python.
There's no need to build your own. Use the Python 3.1.1 OS X installer from python.org. It's 32-bit only and will work just fine on OS X 10.4 through 10.6. If you need to install any packages with C extension modules on 10.6, you'll need to install the optional 10.4 SDK from the the Snow Leopard Xcode mpkg and you'll need to tell Distutils to use GCC 4.0:
$ export CC=/usr/bin/gcc-4.0
I'd try CFLAGS=-m32 LDFLAGS=-m32 although I don't have the requisite hardware to test that it works.
I'm not familiar with the --with-universal-archs option -- must be specific to OS X?