linux_mint17.3, python2.7, which pillow - python

linux python and pillow:
I just upgraded to mint 17.3. The docs say this is an Ubuntu14.04 Kernel.
I wish to run python and the python imaging libarary => pillow.
When I run > python < (command line) i get as follows;
grumpy#grumpy-desktop ~ $ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
I am assuming that python2.7.6 is the default module used. Within usr/
lib/ python2.6, python2.7, python3 and python3.4 all exist.
However; I have been unable to get the version of PIL or Pillow being used.
PIL exist in usr/lib/python3/dist-packages/PIL, along with
~/Pillow2.3.0.eggs-info (not much help here.)
The docs indicate that Linux mint17.3, with an Umbuntu14.04 Kurnel and
python2.7, that Pillow2.3.0 would be most compatable.
So the question is; How to install Pillow2.3.0, with ALL THE MODULES,
for full functionality. I wish to include in scripts;
Image.putpixel(xy, value)
Image.putdata(data, scale=1.0, offset=0.0)
At present when I run the above I get;
AttributeError: 'module' object has no attribute 'putdata' (or 'putpixel')
or, if needed;
How to change python version used, so to install another Pillow version
with full functionality.
Thanks for the input guys.

Related

Terminal shows wrong Python version as default

Typing Python on my Terminal shows
Python 3.9.5 (default, May 4 2021, 03:36:27)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
When in fact I have installed the latest version, 3.10.6, which shows when I type python3 --version. Typing just python --version returns 3.9.5 again.
It seems that the default version is 3.9.5 and not updated, or am I wrong? Either way, how do I solve this? I've tried both downloading and installing it directly, as well as through brew install ..., both giving successful installs, but not updating the default version (3.9.5 -> 3.10.6)
The solution, as provided in the comments, was to create a ~/.zshrc file (How to create a ~/.zshrc file) and then to replace the existing path with export PATH="$(brew --prefix python#3.10)/libexec/bin:$PATH"

default python won't switch to homebew installation

I know this question has been asked - but none of the solutions there seem to be working. I recently found out that on Mac OS, the native installation of python isn't very good. So, I installed homebrew, and installed Python 2 through there. My path is as follows:
~ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin
However, I still get the following:
~ which python
/usr/bin/python
~ which python2
/usr/local/bin/python2
It's also probably important to note that my ~/.bash_profile, ~/.profile and ~/.zshrc files are empty.
Somehow, I think I got pip to work with the python2 (homebrew) installation. Basically, I did pip install pandas and I get the following outputs for the two python interpreters:
~ python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pandas
That is, it doesn't appear with the default python installation. However, I also have the following:
~ python2
Python 2.7.14 (default, Sep 25 2017, 09:53:22)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
>>>
So, pandas is imported in the python2 (homebrew) python, but not the standard one. How can I get it so that the default python is my homebrew python? I also read somewhere that brew link python would work, but when I do that I get
~ brew link python
Warning: Already linked: /usr/local/Cellar/python/2.7.14
To relink: brew unlink python && brew link python
I want to be able to just use python my_file.py and have it use the homebrew installation. (Not sure if it's related, but hopefully this would also allow Sublime to use the homebrew install when I hit command + B).
Sorry for the long post, new computer and I'm trying to get this all correct before I do any big projects and find out halfway through that things aren't working the way I need them to.
Thanks!
The macOS system Python is installed at /usr/bin/python. This is the only one called python on your path.
Homebrew doesn't create a link for python in /usr/local/bin. If you want one you can create it yourself:
ln -s /usr/local/bin/python2 /usr/local/bin/python
Alternatively, just update your shebang lines to specify python2 or python3, which is probably better anyway (explicit is better than implicit).

pip prints trash messages in stdout

When I try to use pip commands, annoying messages are coming out in stdout:
~# pip -V
Platform: linu
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)
~# pip install
Platform: linu
You must give at least one requirement to install (see "pip help install")
Python commands are working normally.
OS - Ubuntu 14.04
I tried to reinstall pip and all dependencies, but it didn't help.
What is that and where it comes from?
The problem was noticed when I tried to use ec2.py dynamic inventory script for AWS. I faced the same problem as here:
https://github.com/ansible/ansible/issues/14667
ec2.py generates JSON with starting "Platform: linu" and therefore ansible doesn't work with that.
Also I searched for boto library (used in ec2.py) and pip configs. But they are blank.
Any suggestions?
Python
~# python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print os.name
posix
>>> import platform
>>> platform.system()
'Linux'
Found one more way to reproduce the issue:
:/usr/bin# python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import os
>>> import boto
Platform: linu
>>>
This is common mistake. Most of this weird problem occur (whether in a plain PC, VM or inside cloud instance such as EC2. Did you notice AWS EC2 using a different locked down pip version) is running Python in sudo mode.
DO NOT run PIP in sudo mode!
My suggestion : setup Virtualenv and install your package on that virtualenv. Then use mkvirtualenv yourenv to create an custom virtualenv.
To load a python script automatically with the designated virtualenv, you just need to put an extra line inside your bash script to trigger your python package/modules.
source <virtualenv_folder>/<virtualenv_name>/bin/activate

Is it possible to use ipython based on a builtin python

I am using paraview 4.3.1 in Centos 7. There is a built-in python named pvpython:
Python 2.7.2 (default, Jan 15 2015, 09:36:49)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys;sys.path
['', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/site-packages/vtk', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/site-packages', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/lib/python27.zip', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/lib/python2.7', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/lib/python2.7/plat-linux2', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/lib/python2.7/lib-tk', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/lib/python2.7/lib-old', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/lib/python2.7/lib-dynload', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/lib/python2.7/site-packages']
>>>
The problem is, original pvpython do not support many useful features such as code completion. And there is no setup_tools in the pvpython, so I cannot install new modules to the built-in python.
Could anyone help me to install ipython on this built-in python?
See the install instructions for get-pip:
https://pip.pypa.io/en/latest/installing.html
However, you must use the pvpython instead of python when using the install instructions.
Depending on how you install it, you may end up with more than one easy_install or pip on your path. Just make sure you're using the one associated with pvpython - look at the script you're running to find out (it's just a shell script).
Once you've done that, installing ipython should be the same as installing it with any other version of python (assuming that pvpython doesn't break anything that ipython needs).

Multiple Python Version Multiple Modules

I have installed on Mac OS X 10.10:
I have installed Python 2.7.6 default apple
2.7.9 python mac ports
and
Pypy.
When i type pip freeze there a lot of modules installed.
However i can import some modules on one python and not the other one, because not everybody finds all modules.
Can someone explain me how can i achieve that every python version find every installed module?
(and does pip show all installed modules?)
As far as i can tell all modules are at : /Library/Python/2.7/sites-packages. But i don't know why not every python looks there.
How about using virtualenv to manage multiple python? https://virtualenv.pypa.io/en/latest/
If you are not sure about which module you are importing, you could try to print the file of the module ( if the module has this attribute). eg:
macbook:~ mac$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt4 as f
>>> print f.__file__
/Library/Python/2.7/site-packages/PyQt4/__init__.pyc
python will search the PYTHONPATH setting and try to load the module, if there are multiple python module with same name, it actually loads the 1st one.

Categories