Installing dependencies using pip in a pre-packaged python install in Windows - python

I am writing a python program to design test scripts using Kivy (a User Interface Library), SQLAlchemy (an ORM), and OpenPyXL (Integration with Excel).
On Ubuntu 14.04, the package installs are very straightforward as all of the libraries install to the system python using pip from the terminal. The program compiles and runs without issue.
However, for Windows 7 & Windows 10, I am having difficulty installing the OpenPyXL Module. This is because Kivy ships as a "Portable" distribution for Windows, which includes it's own instance of Python that is run instead of the system python. The only other option is compiling Kivy from source.
SQLAlchemy can be downloaded with a setup-install.py script, and so I got that installed per the instructions I put up on github:
https://github.com/balex1/TestScriptBuilder
OpenPyXL only lists one installation method, however: pip. So, I am trying to run pip to install OpenPyXL from the Kivy python.exe file. Unfortunately, I see the same error every time. Here's the command from my Windows 10 computer (the path is a bit different on the Windows 7 computer, but the error is the same):
C:\Users\Alex\Documents\Kivy-1.9.0-py2.7-win32-x86\Python27\python.exe C:\Users\Alex\Documents\Kivy-1.9.0-py2.7-win32-x86\tools\pip.bat install openpyxl
The error returned is:
...\pip.bat, line 1
python.exe -m pip %*
^
SyntaxError: invalid syntax
After doing some research, I thought I might be missing something in my PATH Environment Variable, so I tried adding:
C:\Users\Alex\Documents\Kivy-1.9.0-py2.7-win32-x86\Python27\Lib\site-packages\pip
to the environment variable, but this did not work. I then tried adding the pip.exe file that I found in the Kivy Portable Python, but this also failed.
I tend to stick to Ubuntu, so I'm not quite sure where to move from here on the Windows platform. Is there a way to fit the last piece into this puzzle or do I need to compile Kivy on Windows from source?
Thanks in advance for your help!
Sincerely,
Alex

Related

Python launcher tries to run Pip from a Python installation that I've already uninstalled

I am having trouble installing a few modules on my Windows computer (namely TensorFlow). I used to have Python 3.5 and 3.7 installed on this computer, but have since uninstalled Python 3.5 through the Control Panel. However, when I try to check the version of PIP, I get the following error:
Fatal error in launcher: Unable to create process using '"c:\users\yoonh\appdata\local\programs\python\python35\python.exe" "C:\Users\yoonh\appdata\local\programs\python\python35\Scripts\pip.exe" --version'
Meanwhile, following other instructions and using py -m pip ... gives me the following error:
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
I would really appreciate if someone could help me solve this issue! Thank you!
From the information you provided, it looks like you still have Python 3.5 installed for your account locally, or some leftovers from it.
First, if you just uninstalled Python 3.5, make sure that you closed and restarted your command prompt from the Start Menu after uninstalling Python. To be extra sure, restart your system just to ensure that the uninstallation is fully complete (it may not be if e.g. some files from it were in use while you were uninstalling. Windows Installer tells you if this happens and that you need to restart but many users have a bad habit of not reading warnings.).
Run appwiz.cpl as yourself (without elevation) and uninstall Python 3.5 if present
Delete c:\users\yoonh\appdata\local\programs\python\python35 and anything under it; delete it from PATH, too, if present (run SystemPropertiesAdvanced -> "Environment variables")
Check the registry at HKCU\Software\Python\PythonCore and HKCU\Software\Wow6432Node\Python\PythonCore and same under HKLM for any subkeys pointing to installations that don't actually exist

How do I get python to import pandas?

I installed Python 3.5.1 from www.python.org. Everything works great. Except that you can't install pandas using pip (it needs visualstudio to compile, which I don't have). So I installed Anaconda (www.continuum.io/downloads). Now I can see pandas as part of the list of installed modules, but when I run python programs I still get:
ImportError: No module named 'pandas'
How do I set up my environment to use the modules from Anaconda?
Note: I have Anaconda's home directory and Library/bin on my path, as well as Python's home directory. I do not have PYTHONPATH or PYTHONHOME set, and I know I have the correct privileges to see everything.
I have successfully installed pandas for a Windows 32 bit version Python 3.4 with pre-complied code (no Visual Studio required) using the website:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyyaml
There is link for Python 3.5 pre-complied code at this site as well, but I have not tested it.
Download the code you want to a directory on your machine.
Using your Windows CMD.exe, go to your python directory and enter:
Python -w pip install "YourDirectory/pandas-0.18.1-cp35-cp35m-win32.whl"
OR
Python -w pip install "YourDirectory/pandas-0.18.1-cp35-cp35m-win_amd64.whl
Choose the version based on the version of Python you have
have, 32 bit or 64 bit.
Good Luck!
Anaconda has included one version of Python with it. You have to change your system environment path with Anaconda's instead of the former one to avoid conflict. Also, if you want to make the whole process easy, it is recommended to use PyCharm, and it will ask you to choose the Python interpreter you want.

How do I change the kernel/python version for iPython?

I have installed iPython using pip in OS X 10.10, and it gave me the "ipython" and "ipython2" commands, which run great, but which use OS X's default python version 2.7.9. I downloaded and installed the latest release of Python3.4 and can load it with the command "python3," but cannot find a way to get iPython to use this version of python. The iPython Web site states the package can be used with python versions 3.3 and above, but I cannot find any instruction on how to change the default python version used.
So far I have found that the jupyter package for iPython has a kernel specification in /usr/local/share/jupyter/kernels/, which is just a folder called "python2" containing a json file that points to the system's python 2.7.6, but altering this to point to the new python3.4 installation does not work. My guess is this configuration is for the ipython notebook.
I've also tried the approach here: ipython reads wrong python version
In doing so I've duplicated the ipython2 command in /user/local/bin/ and edited it to use the python3 interpreter located at /Library/Frameworks/Python.framework/Versions/3.4/bin/python3, however, this gives me an error "ImportError: No module named 'IPython'," which suggests the python3 installation does not have ipython installed.
To tackle this, I've tried uninstalling ipython and reinstalling it using pip, but it just targets the system's Python 2.7 installation and does nothing for python3.
Does anyone know how to configure iPython to use a different python version, or even install a separate ipython installation for python3? Ultimately it would be nice to quickly switch back and forth depending on my needs.
I just found the answer. In essence, this stems from not understanding the python installation layout and how resources are separated between installed interpreters. It appears each python version will have its own repository of tools, and the current "pip" command I had installed on the system was mapped for use with python 2.7, so all libraries, tools, and other details it managed where available only to python 2.7. This included iPython.
I thought that installing python3 would make all these libraries available to the new interpreter by default, but it appears the system keeps them all separate (which makes sense). The main issue here was continuing to use "pip" which targeted the old installation, instead of the new "pip3" command included with python3. By using pip3 to reinstall iPython, I was able to get iPython3 installed properly.
Unfortunately this setup means needing to re-download other libraries, but that's not too difficult.
It might seem like a trivial issue in hindsight, but this had me completely stuck. I hope this helps someone else in this situation.

Installing Pillow for Python on Windows

I am fairly new to Python and trying to install the Pillow package on Windows 7. I downloaded and ran the MS Windows installer Pillow-2.2.1.win-amd64-py3.3.exe from here. It appeared to install fine. If I run the simple line of code:
from PIL import Image
directly from the Python interpreter, it runs fine. A help() on PIL gives me the package contents.
But when I try to run the same line of code from within a script, I get an ImportError: No module named PIL. What am I missing?
(Note that I've been able to import sys and import MySQLdb from within scripts just fine.)
Resolved: sure, enough, I'm running Python 2.7 when I run scripts. (I think I vaguely recall having to install an older version so I could interface with MySQL.) Thank you all for pointing out that I should check the version being used.
For third-party modules for Windows, my go-to resource is Christoph Gohlke's Python Extension Packages for Windows. You can find the latest version of Pillow here. Make sure you're working with the python.org version of Python.
As far as your specific error, it's hard to tell exactly without a traceback, but make sure your script is calling the correct version of Python. If you have also installed Python 2.7, for example, your script may be calling that instead of 3.3.
In such cases I'm simply printing the sys.path at the beginning of the script in trouble and comparing it with the one from the working python interpreter. In most cases I was running the script with a different python interpreter.
In my case , I was referring to wrong pip folder.
Changed virtual environment in pycharm to point to right pip folder to solve this issue
import sys
print ( sys.path )

Create standalone applications with py2app by not using the system installation of Python on Mac?

I am using py2app to package a Python application to be used on other Mac computers. I am currently running OSX 10.7.5 and the system Python installation on my computer is Python 2.7.1. When I package the program with py2app, it works on my computer, but will not work on another computer - the error that comes up is it cannot locate a Python runtime.
From what I have read about this, it looks like my py2app build is using the system installation of Python on my computer and therefore will only create a semi-standalone application instead of a standalone application.
Also, I have seen that to fix this you need to package it with a separately downloaded Python. I have downloaded a separate Python and even tried to change my PYTHONPATH in my .bash_profile file, but cannot seem to get py2app to build with a different version of Python.
Can anyone point me in the right direction as to how to do this?
I have read other questions and wasn't able to find out how to do it in my case. If there is any other information you need to know to help, please let me know.
py2app builds the application bundle using the running version of python. To use the separate install of python you therefore have to make sure that py2app and the other libraries you use are available in that installation of Python, then use that installation to build the application.
For example:
$ /Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install py2app
$ .../bin/easy_install ...
$ /Library/Frameworks/Python.framework/Versions/2.7/bin/python setup.py py2app
The simplest way of handling this IMO is by utilizing MacPorts. You can download and install a standalone version of Python and just about any other package you might need.
Get macports: https://www.macports.org
sudo port install py27-py2app
sudo port select python python27
Now your standalone Python is the default, and py2app will run and bundle using that version of Python.

Categories