Using Python Image Library with VirtualEnv on Windows - python

I'm attempting to install the PIL library in an Virtual Enviroment that I have created.
Usually to install PIL I'd grab the install, however this won't allow me to choose my virtualenv only my root Python folder (C:/Python26).
I tried both pip install PIL and easy_install PIP but they didn't work. I've also tried downloading the TAR, extracting and running setup.py install
Django is still rejecting my model which contains an ImageField(). Does anyone have a solution?
An error which commonly occurs is below:
Unable to find vcvarsall.bat
Edit:
OK I tried a fresh virtualenv and used easy_install which isn't showing the compile error.
I then open a Python shell and it allowed me to import PIL and import _imaging, however when I try to use the ImageField() in django my models still won't validate.

Rename from PIL-1.1.7-py2.6-win32.egg to PIL in site-packages dir.

OK this appears to be a VirtualEnv problem.
Despite making a new VirtualEnv with the --no-site-packages argument, my Django site is fetching the django files from the root install C:/Python26/Lib/site-packages/ rather than locally.
Django then attempts to fetch PIL in the root site-packages which it cannot find and results in an error.
I have no idea why this is occurring. If I open the python interpreter the root django files do not appear on the path.
Once remedied easy_install PIL should work.

Do you have (the latest version of) Visual Studio installed?
That's where vcvarsall.bat comes from, and what building any Python extension from C sources on Windows would prefer to use (there are ways of using mingw instead, if that's your actual problem).
(I'm saying "the latest version" because I believe that's what the python.org distribution of Python 2.6 for Windows is built with).

Related

Issue to installing module in Thonny (Python text editor)

I downloaded Thonny (which is a text editor for python) for using my Raspberry Pi Pico, and I tried to install a module in "Manage packages", when I began the installation, this error line code appeared:
ERROR: Can not combine '--user' and '--target'
Process returned with code 1
Fortunately there is another way to install modules and I tried it:
Install from a local file: I installed the package in cmd pip install Adafruit-SSD1306 in target directory of the Thonny's modules C:\Users\33631\AppData\Roaming\Python\Python310\site-packages, but I still don't see the module I installed.
After that, I figured out I can't install modules at all, and it brings me the same error message.
I use:
Python version: 3.10
Pip version: 22.3
Thonny version: 4.0.1
I tried many things, change the directory, install with the cmd and research with the Install from a local file, but it is still not working.
I use also the Thonny editor several years, but have never used his Tool | Manage packages... function. I use always pip install ... instead.
If you open this dialog, it shows you a Target path something like C:\Users\your_user\AppData\Roaming\Python\Python311\site-packages, depending on your phython version and path. I assume that python packages are installed always under the phython directory like C:\Python311\Lib\site-packages. My Thonny editor is olso there. Have you searched into python site-packages directory, too?

Problems with installation of Pillow

I am running Python 2.7.1.1 with Anaconda2 4.0.0 64-bit on a Windows 7 machine. I'm trying to install Pillow for imaging, and after having read through every thread I could find, I am still unable to reach a solution. I have installed and uninstalled Pillow through various means including:
pip install Pillow
conda install Pillow
easy_install Pillow
I've gone to the Anaconda site-packages list and, lo and behold, the package for Pillow-3.2.0-py2.7.egg-info exists.
I've tried importing the package through both:
import Image
from PIL import Image
But I encounter the following ImportError:
from PIL import Image
ImportError: No module named PIL
I've already uninstalled the original PIL library that I tried to install to ensure that only the Pillow package exists. Any help would be greatly appreciated!
It sounds like Anaconda isn't playing nice with your system due to the fact that you have two interpreters installed (Anaconda's and Python 2.7.1.1). I would remove everything (Python, Anaconda, etc) and either reinstall Anaconda fresh, or the get the newest version of Python from python.org (2.7.12).
Personally, I'd go for the Python 2.7.12 from python.org (I've always had issues with prepackaged distros like Anaconda).
If you go that route, after your environment is clean I would make sure Pip is all up to date (pip install pip --upgrade) and then install Pillow from whl file provided by the University of California Irvine.
To do that, just go here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Download the Pillow whl file for Windows 64bit. Make sure Python is set up in your path and then just go to the directory where you downloaded Pillow and enter the following (replacing the filename with the one you downloaded):
pip install pillowfile.whl
good luck, and happy coding!
If you can't import a package into Python but it is definitely there in the site-packages folder, then you are more than likely running the wrong Python interpreter.
You can check this by running python from the command line and then entering:
import sys
sys.executable
That will return a string pointing to the current running Python interpreter.
Wrong Python
If that doesn't point to your Anaconda installation then you have a paths problem.
On windows you can set the PATH through My Computer / Properties / Advanced. Look at the Environment Variables and ensure that the Anaconda path string is before any other Python path (If the Anaconda path isn't there, then something is very messed up and you may want to simply re-install Anaconda).
Right Python
If the path returned by sys.executable is correct then the installation of Pillow must be broken somehow. You can try un-installing and then re-installing. As an absolute last-resort you could also try deleting the Pillow folder manually and re-installing it.

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

Windows Python Virtualenv Install PIL and MySQL

In windows I'm having trouble installing things such as PIL and MySQL inside my virtualenv for Python 2.7 64-bit.
I've downloaded extensions from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/ and installed them globally.
But how can I get them to apply to my virtualenv installation?
If I do a re-installation of virtualenv for my project, will it inherit the currently installed PIL and MySQL?
My main error is when I do a pip installed: error: Unable to find vcvarsall.bat
Now what I've read is I need Visual Studio to compile such things, and I'm hoping this isn't the only way to get things working.
Create your environment with the --system-site-packages option. Once you are in the virtual environment, if you try to import a package that isn't installed, it will try to find it in the global site packages and only if it can't find it there will it raise an ImportError.
This is by far the simplest way to do what you are trying on Windows - short of creating your own build environment - which I can tell you from my experience isn't always guaranteed to work.
If you do go with this approach, make sure you still add the package (and ideally pin it) in your requirements.txt file. This way if you were to deploy it on another environment, you will not miss any dependencies.

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