Uninstalling Activestate messed up my python directory and all my settings - python

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.

Related

Installing modules reliably in one location

I've been working with Python for a little while now but have come to absolutely detest installing new modules. It always seems to take me a full work day to install one additional module. This last happened with mpl_toolkits and now it is happening with gdal.
The main issue seems to be that easy_install/pip/get-app aren't saving a file in the correct location and so Python (I'm using Spyder) can't find it. How do I install a module in a location so that Python can find it?
I have been reading guides, articles, manuals and Stack Overflow articles all day now and I feel this needs a new question as I can't find an answer.
It is installing fine, it's just Python (and I) can't find it
It's not in the /lib/python2.7/site-packages folder, which seems to be the Python default, although half the modules that do work aren't in there when I list it
I installed using:
sudo apt-get install gdal-bin
I also tried with:
pip install gdal
but this fails with the error:
Command "python setup.py egg_info" failed with the error code 1 in /tmp/pip-build-NWJT2f/gdal/
I looked for the files using
dpkg -L gdal
and then added the file path this said into Spyder's preferences option for PYTHONPATH, but it still couldn't find it and so I'm guessing this is wrong.
I have read the official documentation of PYTHONPATH, but it's very short and doesn't really explain it at all.
I recommend trying anaconda or miniconda, which manage environments and install packages - it 'just works'.
https://www.continuum.io/downloads

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.

Why does my python installation recognize /Library/Python/2.7/site-packages/?

I have installed Python using Homebrew. I would like for this installation of python to recognize only one site-pakages directory -- /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
However, when I start the python shell and give the command print [f for f in sys.path if f.endswith('packages')] I get the following output:
['/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/Library/Python/2.7/site-packages']
Why is /Library/Python/2.7/site-packages sitting at the end there? Shouldn't the Homebrew installation of Python have just one main site-packages directory under /usr/local/ ???
Edit: I am using virtualenv -- but this is occurring after a fresh install of python using homebrew before I have even had a chance to install virtualenv. Also, I'm interested in why it is happening, not on what I should do to get around it.
Created a stack overflow account just for this, since I was so annoyed by it. I actually had a bug inadvertently caused by that extra "/Library/Python/2.7/site-packages" in the sys.path
Researching it led me to this:
http://bugs.python.org/issue4865
tl;dr: From what I can tell, they throw that path in there to help people that installed packages for the apple-shipped python, but then later would try to use those packages in other versions of python (like the ones used by homebrew, macports, etc).

Python - how can I change default path when installing modules?

I'm trying to install a Python Module by running a Windows installer (an EXE file).
The Problem is that the default python folder and the defualt Installation Library are set To disc D:\ and are grayed out (meaning I can't change it). It might be fine is some places, but in my computer, D is the DVD drive, meaning that no installation is possible.
Is there any way to change this or to overcome this?
It's not "default folder", and there's a reason there's "found in registry" next to the version. You need to re-register the Python installation if you've moved it, either by installing it again (without removing) in the same folder, or changing the directory saved in registry (HKCU\Software\Python\PythonCore\X.X\InstallPath, possibly on Wow3264Node) either manually or using registration script.
Because what you're installing (you don't say what it is) seems to be standard distutils-generated installer (as Cat Plus Plus points out in his comment) you don't have to install it by running installer. You can install it using easy_install program what allows you to choose which Python to use. See my answer to Can I install Python windows packages into virtualenvs? question.
EDIT
Now I see in your comment you're installing setuptools. This complicates things a little bit as this is the package which contains easy_install tool I mentioned above. You have chicken/egg problem here... There's solution for this, however. You can use ez_setup script to install setuptools without using exe installer.

How can I use pywin32 with a virtualenv without having to include the host environment's site-packages folder?

I'm working with PyInstaller under Python 2.6, which is only partially supported due to the mess MS have created with their manifest nonense which now affects Python since it is now MSVC8 compiled.
The problem is that the manifest embedding support relies on the pywin32 extensions in order to build which is a pain because without including the host's site-packages folder when I create the virtualenv (kinda defeats the point in a build environment) I cannot find a way to install the required extensions so they are accessible to PyInstaller.
Has anyone found a solution to this issue?
I found http://old.nabble.com/Windows:-virtualenv-and-pywin32--td27658201.html (now a dead link) which offered the following solution:
Browse http://sourceforge.net/projects/pywin32/files/ for the URL of the exe you want
Activate your virtualenv
Run easy_install http://PATH.TO/EXE/DOWNLOAD
This works with modern versions of setuptools (circa February 2014, reported by tovmeod in the comments).
If you are using an old version of setuptools (or distribute it merged back into setuptools), you may get this error message:
error: c:\users\blah\appdata\local\temp\easy_install-ibkzv7\pywin32-214.win32-py2.6.exe is not a valid distutils Windows .exe
In which case:
Download the exe yourself
Activate your virtualenv
Run easy_install DOWNLOADED_FILE.exe
I rather hopefully tried "pip install" rather than "easy_install", but this didn't work, and likely never will (citation needed).
Finally, I found but haven't tested a solution at http://www.mail-archive.com/python-list#python.org/msg272040.html which is:
Solved this by copying the pywin32.pth file into my virtualenv site-packages
and editing the file to point to the path.
If the other options don't work for you, maybe this will?
For Python 2.7 or 3.x use pypiwin32.
pip install pypiwin32
OK, well since I had to find a way forward I improvised. I've internally created a git repository with a hacked-together version of pywin32 that will install within a virtualenv using the standard setup.py script. It took a lot of fiddling to make it work right but I managed to get it to load and the dependent code now works as I need it to. If people feel this would be of benefit to the community please post a comment: if I get enough I'll try and put something up on my github account.
This may have been improved since previous answer, since I've successfully installed pywin32 on sandbox on several machines without any specific "hacks" :
$ virtualenv sandbox
$ sandbox\scripts\activate
(sandbox) $ git clone https://github.com/Travis-Sun/pywin32.git
(sandbox) $ cd pywin32
(sandbox) $ python setup.py install
Tested with following environment :
windows 7
git
python 2.7.10 with virtualenv
VS2008. It may also work (but I've not tested yet) with
http://www.microsoft.com/en-us/download/details.aspx?id=44266
Edit: Scratch this for now, appears to be some problems with the installation still...
I got rather tired of the whole situation, and just created a set of converted wheels ("wheel convert <.exe>"). I'll try and keep them maintained for the most recent build, but do shout if there are any issues.
https://tr00st.co.uk/python/wheel/pywin32/
Installation can be done easily using pip and pointing to the package matching your version and architecture. For example, for Python 3.5/amd64:
pip install https://tr00st.co.uk/python/wheel/pywin32/pywin32-219-cp35-none-win_amd64.whl
Caveat: The --upgrade process currently fails, as the uninstall procedure is unable to clean up after itself (Access Denied when cleaning up win32api.pyd) - this is only when removing the temporary directory, which can be manually deleted. Easiest way around this is to uninstall and reinstall instead of upgrading, then manually delete the temporary folder.

Categories

Resources