I'm getting the following error when I try to install using pip install for PyMVPA2 for Python. I have installed other libraries without any problems before. I would appreciate if anything could take a look at the errors:
C:\Users\usr>pip install pymvpa2
Collecting pymvpa2
Using cached pymvpa2-2.4.2.tar.gz
Complete output from command python setup.py egg_info:
running egg_info
running build_src
build_src
building extension "mvpa2.clfs.libsmlrc.smlrc" sources
building extension "mvpa2.clfs.libsvmc._svmc" sources
creating build
creating build\src.win32-2.7
creating build\src.win32-2.7\mvpa2
creating build\src.win32-2.7\mvpa2\clfs
creating build\src.win32-2.7\mvpa2\clfs\libsvmc
swig.exe++: mvpa2\clfs\libsvmc\svmc.i
swig.exe -python -I3rd\libsvm -c++ -I3rd\libsvm -o build\src.win32- 2.7\mvpa2\clfs\libsvmc\svmc_wrap.cpp -outdir build\src.win32-2.7\mvpa2\clfs\libsvmc mvpa2\clfs\libsvmc\svmc.i
error: command 'swig.exe' failed: No such file or directory
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\usr\appdata\local\temp\pip-build-v_zzkd\pymvpa2\
As the error states you either don't have swig installed or it is not on your path. You are obviously on Windows so you need to download the swig executable from the swig website - download the latest windows package and either unzip it to a directory on your existing path or to a new directory and add it to your path. Easiest, of course, is to unzip it to a new directory and then run your pip command in that directory.
What is swig anyway? Swig parses the interface definitions of code written in C/C++ and can output 'glue code' to allow code written in Python & a pile, currently 22, of other programming or scripting languages to use the C/C++ code transparently. Swig is free, open source and compatible with both open source and commercial use.
Should I keep it to hand? In most cases that I know of in python swig is only invoked during the installation or setup phase but since that setup phase will be used every time that any package built with swig is installed or upgraded there is no reason to get rid of it and quite a lot of reasons to have it somewhere on your path.
sudo apt-get remove swig
sudo apt-get install swig3.0
sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
and then
pip install pymvpa2
Is there a way to explicitly force the compiler for building Cython extensions when running python setup.py install? Where setup.py is of the form:
import os.path
import numpy as np
from setuptools import setup, find_packages, Extension
from Cython.Distutils import build_ext
setup(name='test',
packages=find_packages(),
cmdclass={'build_ext': build_ext},
ext_modules = [ Extension("test.func", ["test/func.pyx"]) ],
include_dirs=[np.get_include()]
)
I'm trying to install a package on Windows 8.1 x64 using Anaconda 3.16, Python 3.4, setuptools 18, NumPy 1.9 and Cython 0.24. The deployment script is adapted from the Cython wiki and this Stack Overflow answer:
Makefile.bat
:: create and activate a virtual environement with conda
conda create --yes -n test_env cython setuptools=18 pywin32 libpython numpy=1.9 python=3
call activate test_env
:: activate the MS SDK compiler as explained in the Cython wiki
cd C:\Program Files\Microsoft SDKs\Windows\v7.1\
set MSSdk=1
set DISTUTILS_USE_SDK=1
#call .\Bin\SetEnv /x64 /release
cd C:\test
python setup.py install
The problem is that in this case setup.py install still used the MinGW compiler included with conda instead of the MS Windows SDK 7.1 one.
So the DISTUTILS_USE_SDK=1 and MSSdk=1 don't seem to have an impact on the build. I'm not sure if activating the MS SDK from within a conda virtualenv might be an issue here.
Running python setup.py build_ext --compiler=msvc correctly builds the extension with the MS compiler, but subsequently running the setup.py install recompiles it with MinGW again. Same applies to python setup.py build --compiler=msvc.
Also tried running %COMSPEC% /E:ON /V:ON /K "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" as discussed in the answer linked above, but for me this produces a new terminal prompt, colored in yellow, and stops the install process.
Is there a way of forcing the compiler for building this package, for instance, by editing the setup.py?
You can provide (default) command line arguments for distutils in a separate file called setup.cfg (placed parallel to your setup.py). See the docs for more information. To set the compiler use something like:
[build]
compiler=msvc
Now calling python setup.py build is equivalent to calling python setup.py build --compiler=msvc. (You can still direct distutils to use an other complier by calling python setup.py build --compiler=someothercompiler)
Now you have (successfully directed distutils to use a msvc compiler. Unfortunately there is no option to tell it which msvc compiler to use. Basically there are two options:
One: Do nothing and distutils will try to locate vcvarsall.bat and use that to setup an environment. vcvarsall.bat (and the compiler it sets the environment up for) are part of Visual Studio, so you have to have installed that for it to work.
Two: Install the Windows SDK and tell distutils to use that. Be aware that the name DISUTILS_USE_SDK is rather missleading (at least in my opinion). It does NOT in fact tell distutils to use the SDK (and it's setenv.bat) to setup an environment, rather it means that distutils should assume the environment has already been set up. That is why you have to use some kind of Makefile.bat as you have shown in the OP.
Side Note: The specific version of VisualStudio or the Windows SDK depends on the targeted python version.
As a remark: on linux, you can use many of the autoconf environment variables. For the compiler
CC=mpicc python setup.py build_ext -i
Well I found a trick in my case : I wanted to use MSVC14.0 (from buildtools 2015) and NOT MSVC14.1 (buildtools 2017). I edited the file Lib\distutils_msvccompiler.py. There is a method
_find_vcvarsall
which is calling
best_version, best_dir = _find_vc2017()
I replaced this call by
best_version, best_dir = _find_vc2015()
Do not forget to undo this dirty trick once compiled.
I ended up putting this at the beginning of setup.py to force visual2015
useful when running in a non bat environment and starting vcvarsall from outside is not an option
if sys.platform == 'win32':
# patch env with vcvarsall.bat from vs2015 (vc14)
try:
cmd = '"{}..\\..\\VC\\vcvarsall.bat" x86_amd64 >nul 2>&1 && set'.format(environ['VS140COMNTOOLS'])
out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, universal_newlines=True)
except:
print("Error executing {}".format(cmd))
raise
for key, _, value in (line.partition('=') for line in out.splitlines()):
if key and value:
os.environ[key] = value
# inform setuptools that the env is already set
os.environ['DISTUTILS_USE_SDK'] = '1'
There is a --skip-build option of install command which will help you with this. You can also specify multiple commands in a row, like so:
python setup.py build --compiler=msvc install --skip-build
Here is a list of supported compiler types (as returned by setup.py build_ext --help-compiler):
--compiler=bcpp Borland C++ Compiler
--compiler=cygwin Cygwin port of GNU C Compiler for Win32
--compiler=mingw32 Mingw32 port of GNU C Compiler for Win32
--compiler=msvc Microsoft Visual C++
--compiler=unix standard UNIX-style compiler
Note: To prevent compatibility issues extension modules should be built with the same compiler as the Python interpreter itself.
I have a C++ logic which I'm calling from Python. I have created a setup.py using distutils to build and install. The C++ logic has a cmake file. To build the C++ this cmake file needs to be incorporated into the setup.py file. How can I do this? Below is my cmake file for the C++ code.
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
set(name "facerec")
project(facerec_cpp_samples)
#SET(OpenCV_DIR /path/to/your/opencv/installation)
# packages
find_package(OpenCV REQUIRED) # http://opencv.willowgarage.com
add_executable(fisherfaces_app fisherfaces_app.cpp)
target_link_libraries(fisherfaces_app opencv_contrib opencv_core opencv_imgproc opencv_highgui)
Below is my setup.py file.
from distutils.core import setup,Extension
extension_mod=Extension("getGender",["getGender.cpp"])
setup(name="getGender",ext_modules=[extension_mod])
I am new to embedded python and cmake. Please advice on how to do this.
So rather than messing it up with both cmake and setup.py, I incorporated the Python header file into cmake and built a shared library. Then used this shared library to call my functions from Python. My cmake is as follows,
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
set(name "facerec")
project(facerec_cpp_samples)
#SET(OpenCV_DIR /path/to/your/opencv/installation)
# packages
find_package(OpenCV REQUIRED) # http://opencv.willowgarage.com
find_package(PythonLibs REQUIRED)
include_directories(/usr/include/python2.7)
add_library(getAge SHARED getAge.cpp)
target_link_libraries(getAge opencv_contrib opencv_core opencv_imgproc opencv_highgui python2.7)
I have a python project in which I have to execute this command every now and then.
python setup.py build_clib
followed by
python setup.py build_ext --inplace
I want this to happen with just a single line code of python setup.py build but that is not possible because I want my .so file inplace.
Is there any possible way of doing this?
You need to add these lines to your setup.cfg file.
[build_ext]
inplace=1
I got Cython 0.15 and tried to install it like this
python setup.py install
I get this:
running install
running build
running build_py
running build_ext
building 'Cython.Plex.Scanners' extension
error: Unable to find vcvarsall.bat
What does this mean? I have Micorsoft Visual Studio 2008 and Windows SDK. Using Windows 7, python 2.6
I have no direct answer to your question, but I would strongly recommend to give this pre-built Cython package a try.