Failing to build Slycot on windows 7 using anaconda distro - python

I'm trying to build slycot, a python wrapper around the fortran library SLICOT.
I'm using the anaconda python distribution Anaconda-2.0.1-Windows-x86_64 on a 64-bit windows 7.
The first naive python setup.py build command resulted in
NotImplementedError("Only MS compiler supported with gfortran on win64")
So far so good. After googling for a while, someone recommended simply commenting out the line in numpy. This seems to work. gfortran is called and all the libraries are compiled, but then it fails at linking with the following message
The command line is too long
It seems that listing all the *.o files generates a huge command string which can not be processed.
Any suggestions?

If you are still having this problem, try upgrading to Anaconda-2.1.0. If that still fails and you are not tied to Python2, then install a Python3 environment using the Anaconda3-2.1.0-Windows-x86_64 distribution. Once I did that and a manual package install (steps below) I didn't get the "command line too long" error. I have Anaconda installed in C:\Anaconda - can't tell if that helped or not.
To manually install a package:
Download the package you need (for me it was numpy).
Extract to a directory (I used c:\temp).
Fix gnu.py in the distutils\fcompiler subdirectory per instructions here.
Exit any apps using python and kill any remaining python.exe processes with task manager; not doing this caused my first compile to fail.
Open an Anaconda Command Prompt (a standard admin cmd.exe window will not work).
If you have multiple environments, activate the correct one.
Change to the directory you extracted your package to.
Type python setup.py install

Related

How to start using `scipy`

I have previously installed Python 3.4.2 and 3.5.2 and in both cases I can dabble in writing and testing code in Idle which gives me two windows -- a "Run" window for code, and a "Shell" window for interaction and output (sorry, not sure of the correct terminology).
Now I'd like to try out scipy, particularly scipy.spatial.
First, I downloaded WinPython (WinPython-64bit-3.4.3.6Qt5.exe) from sourceforge.net/projects/winpython/files/ but when I tried to install it, it wanted to put it in my Downloads folder (where the installer was saved, obviously) so I browsed to Program Files and tried to install there but I get
Error opening file for writing
C:\Program Files\WinPython-64bit-3.4.3\IDLE (Python GUI).exe
Same response at C:\Program Files (x86)\.
Next, I downloaded just scipy-0.16.1-win32-superpack-python3.4.exe and it seemed to be successfully installed until I try to run import scipy in my usual "Run" window I get
ImportError: No module named 'numpy'.
Third, I retried WinPython-64bit-3.4.3.6Qt5.exe again, but this time accepting the default Downloads install location. This time there was a successful installation of python-3.5.1.exe in Downloads. When I ran it I chose "Repair" and eventually got "Repair was sucessful." However, when I try to run import scipy in my usual "Run" window I get
ImportError: No module named 'scipy'.
What steps am I missing? What is the easiest way for me to try using scipy?
Assuming you have correctly installed Python, you can try using the .whl (wheel) files available on the LFD's website.
First, make sure you have an updated version of pip which supports the use of .whl files by using the following command in the terminal:
python -m pip install -U pip
Then, download the latest versions of the .whl files for NumPy and SciPy into some directory you can easily locate.
Afterwards, use the following command to install the .whl files you've downloaded in the necessary order:
python -m pip install C:/path/name-of-file.whl

error in installing matplotlib1.5.1 in python3.5

I have 'Windows 8'. I installed 'python35-32' successfully. Then I download 'matplotlib 1.5.1' . But it can not installed . I get an error that required package can not be built.
Try this:
Open cmd with admin privilege. (right click and Run as administrator)
Enter this command pip install matplotlib, and wait for the installation to complete.
Alternative:
If you want to keep the wheels for offline installation later, you can do the following:
Open cmd, and enter this command
pip install --download /path/to/some/dir/ matplotlib. This will download matplotlib and all other required wheels in the directory /path/to/some/dir/.
To install, enter this command: pip install --no-index --find-links /path/to/some/dir/ matplotlib
Here /path/to/some/dir/ is the directory where the file gets downloaded. You can use . instead of /path/to/some/dir/ to download in the current directory.
Edit:
Take a look at matplotlib installation guide for windows. The line most relevant to your case is probably this:
For Python 3.5 the Visual C++ Redistributable for Visual Studio 2015 needs to be installed.
So just install it by following the link and then follow the above procedure. That should do the trick.
Note: They also suggest that the best option is using one of the pre-packaged python distributions that already provide matplotlib built-in, like Anaconda, miniconda and canopy. You may want take into consideration too.
Edits as per your comment
As I have already said, anaconda is a pre-packaged python distribution that includes hundreds of python packages. To quote the official python page, anaconda is "a full Python distribution for data management, analysis and visualization of large data sets". So you can do pretty much everything with anaconda that you can do with the traditional python (aka CPython), plus you have a great number of popular python packages at your disposal.
To get yourself started with anaconda, you can check this out: Test drive Anaconda.

How to install the optimization pack pyOpt in Python on windows

I have Anaconda pack for Python installed on my windows 7 laptop.
I followed all the installation steps as explained at:
http://www.pyopt.org/install.html#installation
After some trial and error, I could install pyOpt using the following command:
python setup.py install --compiler=mingw32
But still, I can't run even the simplest tutorial example at ..
http://www.pyopt.org/tutorial.html
.. maybe because the optimizer SLSQP is missing in the installation. I get following error message when I run the tutorial example:
slsqp = pyOpt.SLSQP()
AttributeError: 'module' object has no attribute 'SLSQP'
How can I install pyOpt completely with optimizers etc. on windows?
I'm going to preface this with: I know very little about what I am doing...
I've been stuck on this for a long time too. I have a feeling it has something to do with how the modules are built during installation. I think the pyOpt modules all point to fortran and c libraries which are "translated" to python when you run
python setup.py install --compiler=mingw32
I have been playing around using different compilers and command environments (administrator privledges, powershell, cygwin, etc.) to no avail. The msvc compiler fails at a certain point. Cygwin, MinGW32, IntelEM, all compile but produce the same error when going to run the actual examples.
If you look in the C:\PathToPython\Lib\site-packages\pyOpt\ folder you'll see the folders with all the modules. When you call import, you're importing these modules... so by entering the following (for example... I think):
from pyOpt import pySNOPT
you are more or less instructing the imports to navigate through the folders to find pySNOPT and import it ... I think. You'll notice that in \pyOpt\pySNOPT\ there is a file pySNOPT.py. When importing, using from pyOpt import SNOPT it looks in pyOpt for SNOPT.py... but you'll find (as python has) that there is NO such file to import. Instead, there is only a pySNOPT.py. Knowing this we would expect the following to fix the problem:
from pyOpt.pySNOPT import pySNOPT
But this, too, fails. This time producing an import error stating "SNOPT shared library failed to import" (this is a pretty big clue, I suspect).
If you open the pySNOPT.py (this could be replaced with the acronyms for any of the other solvers) file you'll see the familiar format of a python module staring back at you. The first lines of all of these files goes something like:
try:
import snopt
except ImportError:
raise ImportError('SNOPT shared library failed to import')
This is where the breakdown occurs. The "import snopt" line is supposed to load the snopt.dll (snopt.so, snopt.a for Linux, Unix). When running setup.py, if I use a cygwin environment it creates DLLs in each of the C:\PathToCygwinDrive\lib\python2.7\site-packages\pyOpt\pyACRONYM folders. These DLLs do NOT appear to be placed in the location corresponding to the version of Python I am telling PyCharm to use (c:\PathToPython\Lib\site-packages\pyOpt\pyACRONYM). I used all of the compilers (including cygwin) in other environments (powershell, Visual C++ 2008 64-bit command prompt, any other command prompt for that matter). Simply copying and pasting the DLLs from the Cygwin pyOpt folder to the regular Python pyOpt folder did not work. I don't know if there's a special way that DLLs have to be imported or something. Reading up on building C extensions and linking them to python projects got over my head and tedious way too fast.
I thought this was local to my computer (since a group member managed to get his installation working) but when going through setup on another group member's computer I ran into the EXACT same error.
One important thing to note... I am doing everything in x64 architecture (as was the group member who I tried to help but also got stuck here). This might be the real secret to fixing this. Perhaps there are too many hoops to jump through to get pyOpt working on 64-bit Python. Which brings me to my last point... there some workarounds I can think of:
install 32-bit Python, restart the process.
install Spyder IDE (through anaconda or something), then install pyOpt using:
conda install --channel https://conda.anaconda.org/melund pyopt
or
conda install --channel https://conda.anaconda.org/mutirri pyopt
(both for x64 windows)
DO NOT use the default conda pyOpt (conda install pyopt) as this is version 0.84 and will not work.
Switch to Linux (since programming with linux is like using lube with anal... you CAN make it work without it... but everything will be a lot more painful)
These are the workarounds I've found so far. I hope someone posts an actual solution SOON!
I succeeded to install pyOpt on Win64 on Anaconda. Here is how:
One can use the command from the comment above to install pyOpt 1.2 from mutirri channel:
conda install --channel https://conda.anaconda.org/mutirri pyopt
Installation goes almost smoothly. With the only exception that it asks to install Microsoft MPI package in order for pyOpt to work properly (that is easy: just go to https://www.microsoft.com/en-us/download/details.aspx?id=49926 and download the latest installer).
However, when we try to run some test script for pyOpt, an attempt to use the SLSQP solver fails. Surprise! So, some research is needed.
If we load Lib\site-packages\pyOpt\pySLSQP\slsqp.pyd file into Dependency Walker we can see that LIBGFORTRAN-3.DLL file is missing.
Quik google search shows that LIBGFORTRAN-3.DLL file comes bundled with MinGW64. So, we need to download and install MinGW64 using installer from here:
https://sourceforge.net/projects/mingw-w64/files/mingw-w64/
Then locate LIBGFORTRAN-3.DLL in the mingw64\bin folder and copy all DLLs from this folder somewhere into the PATH (I just copied all mingw64 DLLs to C:\Anaconda2\Library\bin).
Now SLSQP solver works!
I had a similar problem when using pyOpt on Windows, I couldn't use any pyOpt library that were written in fortran. The above solutions didn't work for me so I add my own answer here, I hope it helps:
Install these libraries:
conda install libpython
conda install -c msys2 m2w64-toolchain
Check if fortran compiler are available:
f2py -c --help-fcompiler
You can install one:
conda install -c conda-forge fortran-compiler
Delete or uninstall any prior version of pyOpt
Download pyOpt-master from https://github.com/madebr/pyOpt
Go in the appropriate folder and try to run the following line in anaconda prompt:
python setup.py install --compiler=mingw32
If the option --compiler is not recognized, try to run the following lines:
python setup.py build --compiler=mingw32
python setup.py install
If it doesn't work try the following:
Go in the following directory (or equivalent):C:\Users...\Anaconda3\Lib\distutils
Open or create file distutils.cfg
(You can do it with the following line if you have notepad, it will create and open the file):
notepad distutils.cfg
In distutils.cfg add these two lines:
[build]
compiler=mingw32.exe
Then go back in the pyOpt master directory and run this line in anaconda prompt:
python setup.py build --compiler=mingw32
If it worked:
In distutils.cfg, remove '.exe', so you have these two lines:
[build]
compiler=mingw32
And run this line:
python setup.py install
If everything went well pyOpt should have appeared where you wanted (in my case, C:\Users...\Anaconda3\Lib\site-packages).
You can try to run python examples\parallel_gradient.py or any other exemple to see if it worked.
I think it should do but other things I have done before might be necessary:
If this doesn't work, try that:
If you have installed mingGW with conda, uninstall it, I think you can do it with:
conda uninstall -c anaconda MinGW
Download the latest version of mingw-w64: http://mingw-w64.org/doku.php/download/mingw-builds
In Anaconda3\DLLs you may put:
libatomic-1.dll
libgcc_s_seh-1.dll
libgfortran-3.dll
libcomp-1.dll
libquadmath-0.dll
libssp-0.dll
libstdc++-6.dll
libwinpthread-1.dll
One was already there, libfortran-3.dll was downloaded from internet, the rest are copies from minGW-w64
(I found them in C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin)
The path depends on where you installed minGW-w64 and may depend on your version. Copy ALL the DLL somewhere the sys.path have access to(Anaconda3\DLLs for me).
I got this to work in Windows using 64-bit Python 3:
unzip swigwin and add to environment variables
unzip wingw-w64 and add to environment variables, place at very beginning
Run the following command from the pyOpt folder:
python setup.py install --compiler=mingw32
If you have tried to compile it, you may need to delete the build folder first

Installing QuTIP 2.2.0 with existing Python distribution on Windows

Has anyone managed to install QuTIP 2.2.0 with an existing Python 2.7.5 distribution (on Win7)? The instruction manual suggests that I need to install Python(x,y) first, but the instructions are pretty vague. I'm still a Python newbie.
Understanding installation instructions
The installation instructions are pretty clear, but I remember the times, I got lost in those short lines assuming I know something obvious.
I will try translating it
install Python(X,Y) - do it. Follow the link, download the exe file and run it.
Do not forget to set the options, following defaults will fail, Cython option must be included.
edit the distutils.cfg file as instructed
download tar.gz archive for QuTIP from PyPi, unpack it in some directory, cd into it to be in the directory, where you see setup.py, and run $ python setup.py install
The distutils.cfg refers to mingw32, this is needed for compilation. If it is not installed with Python(X,Y), you would have to install it separately. Be careful and install proper version, even on 64 bit systems use 32 bit one (this I assume from proposed name of compiler in config).
Good luck. I am not on Windows for about 2 years, so I cannot confirm, it works, but I hope, it will move you on.
I also had a lot of problems installing it correctly.
Here is my working solution.
As the installation instructions suggest:
Install PythonXY (I am using 2.7.6.1) (including Cython package) (Edit: The newer versions of PythonXY do not include a compiler. Try installing from here instead: https://code.google.com/p/pythonxy/wiki/AdditionalPlugins)
Edit C:\Python27\Lib\distutils\distutils.cfg to include:
[build]
compiler = mingw32
[build_ext]
compiler = mingw32
Add C:/MinGW32-xy/bin to your PATH. It has to be before other paths with e.g. gcc in them. You can do this:
set PATH=C:/MinGW32-xy/bin;%PATH%
for a temporary add (in that console) or use the answer here.
For a permanent change go properties of your Computer. Go to advanced system settings --> Environment Variables. Change the System Variable to have the MinGW path as the first entry. It doesn't work if it is last or in the user path!
Run a Python interpreter:
import qutip; qutip.testing
qutip.testing.run()
If it doesn't crash on the 7th test you probably have a working copy of qutip.
I get 320 test in 2194.236s and SKIP=7, errors=5.
Details of which tests failed for my can be seen here.
I would use Anaconda 2.7 with the added mingw and libpython libraries and then edit the distutils.cfg as stated. The skipped tests mentioned are fortran tests that you cannot run on windows, while the errors are time dependent tests that generate cython code at run time. If you follow the above suggestions then those tests will pass.
I've tried to install qutip for several hours, unsuccessfully. Fortunately, kind people from University of California have a solution:
wheels for lots of packages for python computing
This resource is not official, 'as is', but works better!
Type 'pip install package.whl' to download and build.

Uninstalling Activestate messed up my python directory and all my settings

So I was really eager to try generating a django model diagram with django-extensions by doing the following:
manage.py graph_models -a -g -o my_project_visualized.png
Then I realized I need pygraphviz to make it work. I'm running Windows 7 64bit, so I installed Activestate and Graphviz as suggested by the documentation as a requirement. Graphviz 2.28 was installed quite successfully and then Activestate was installed with some tweaks msiexec /package activestate_install.exe /qr because it always stuck at "finish checking disk spaces required".
Later, it turns out activestate wasn't really helping in installing pygraphviz. So after a lot of trial and errors, I managed to install pygraphviz by following this guide http://blog.ropardo.ro/2011/11/28/installing-pygraphviz-on-windows/. Just as I tried to run the graph_models command again, python once again tells me that pygraphviz module is not installed... so I pip freeze to see if it's really not installed. Now comes the good part, pip freeze returns a traceback of ImportError: DLL load failed: %1 is not a valid Win32 application. But that only happens in virtualenvs, when get out of virturalenvs and pip freeze, it works as expected.
By googling around, I realized I might have installed some 64bit version package while having 32bit python 2.7.3 on my machine, and that's indeed what I did. Just that I don't remember which ones I installed were 64bit. It's late at night, and I'm tired and frustrated, so I started uninstalling things that I thought might be causing the problem. I uninstalled mingw32 and Activestate, and the next thing I know, I can't even get into python from command line. pip is not recognized either; every python package is not recognized. Checking back at the Python27 directory, half of the folders are gone in C:\Python27\Lib. There used to be a lot of files and folders which it's impossible for me to recall what they are, and now there's only 4 directories:
bsddb, importlib, site-packages, and test
and the site-packages folder is a lot "cleaner", too! I'm sure there used to be a lot of package files and scripts (some .pth files and .py files). Now there's only two files easy-install.pth and PIL.pth and some folders for some packages I installed. However, the most critical issue is I can't even use python in cmd now.
I thought maybe uninstalling activestate messed up some of the environmental variables I set, then I went into the system settings and added in things like C:\Python27\Scripts;C:\Python27\Lib\site-packages to PATH. I went back into cmd, and typed "python" and "pip", the response I get for python is The system cannot find the path specified., and for pip it's still 'pip' is not recognized as an internal or external command, operable program or batch file.
This is kind of the only time that I regret for not setting up a system restore point..
Could anyone please tell me what's going on here, what am I doing wrong, and how am I supposed to get everything working again? Thanks a lot!
Boy, you indeed messed up your installation. "ActiveState" is a python distribution for Windows, so you installed a new python distribution over your old one. When you uninstalled, it obligingly removed your python installation, including the default library.
You'll have to reinstall your Python installation, I'm afraid. Start from scratch or backup.
You have my sympathies, if that's any consolation.

Categories

Resources