How to install ipython or flask and there dependences in virtualenv? - pip

I have learned the dependences should be installed automatically, but it only install itself when I install flask in a virtualenv.
Installing collected packages: flask
Successfully installed flask-0.12.2
➜ ~ python
Python 3.6.2 (default, Sep 15 2017, 07:44:18)
[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.
>>> from flask import Flask
Trceback...
...
ModuleNotFoundError: No module named 'werkzeug'
Then I have to install werkzeug and re-import Flask
but:
ModuleNotFoundError: No module named 'jinja2'
After install jinja2, there still markupsafe, itsdangerous (etc) to install to run Flask.
Solved
I forgot when did I set 'no-dependences = True' in .pip/pip.conf.
Now it's okey after detele the line.

My suspicion is that you've either
installed packages into virtualenv but receive these errors when the virtualenv is not activated i.e. when interpreter has no access to those packages
or
vice versa i.e. installed packages globally and then activated virtualenv, where by default the only pre-installed packages are pip, setuptools, and wheel.
I would suggest activating the virtualenv [from dir holding venv, run . <venvName>/bin/activate] and checking packages available [pip list]. Then, deactivate and check global packages available.

Solved
I forgot when did I set 'no-dependences = True' in .pip/pip.conf.
Now it's okey after detele the line.

Related

Unable to install python3.7.x in mac

I am pretty new in mac version 12.6 . I tried to install python 3.7 in my mac for trying out some legacy project but I am unable to.
I tried two was downloading the .pkg file from python.org and also by pyenv
While the .pkg says successfully installed and pyenv versions gives me 3.7.13 .
While trying python3.7 or python3 from terminal I am getting
% python3
zsh: killed python3
% python3.7
zsh: killed python3.7
But my other versions working fine like
% python3.9
Python 3.9.13 (v3.9.13:6de2ca5339, May 17 2022, 11:37:23)
[Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
How to fix this isssue.
I usually use pyenv to install and manage Python versions. (You can install it using Homebrew)
1- pyenv install 3.7.0
#To see the list of the Python versions
2- pyenv versions
#To set the newly installed version as the default
3- pyenv global 3.7.0
Now, run python3 --version
if the output is NOT 3.7.0 then you need to add the following lines to your .zsh or .zshrc file:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
and finally update your .zsh or .zshrc file:
source .zshrc or source .zsh

Should I use pip or pip3 to install python3 packages inside of a virtual environment?

I have python 2(as default) and 3 on my Linux machine. I created a virtual environment to try out pandas with python3. So, I ran:
virtualenv -p python3 pandas_env
If I type python inside of this env it goes to the standard python shell, with python 3 as the default version
(panda_env)$ python
Python 3.4.3 (default, Sep 14 2016, 12:36:27)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
To install ipython, I did:
(panda_env)$ pip install ipython
now, running ipython, it defaults to python2 instead of 3
(panda_env)$ ipython
WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
Type "copyright", "credits" or "license" for more information.
IPython 2.3.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
With a WARNING saying to install ipython inside virtualenv. I thought did installed ipython inside the environment, and why is it using python2.x by default?
How do I install ipython inside virtualenv correctly, and how can I make ipython use 3.x instead of 2.x?
Also, should I use pip or pip3 to install packages inside a virtualenv?
Note, for python > 3.3 it's recommended you start a virtual environment with the pyvenv command. This has now been deprecated as of python > 3.6 in favor of python3 -m venv <environment name> (via https://docs.python.org/3/library/venv.html)
In answer to your question, I don't believe it matters based on this check:
# start enviroment
$ python3 -m venv test_env; source test_env/bin/activate
# check python version
(test_env) $ python --version
Python 3.6.0
# check pip and pip3
(test_env) $ which pip
~/Documents/test_env/bin/pip
(test_env) $ which pip3
~/Documents/test_env/bin/pip3
# The pip commands are different, but if we check their versions they are the same and both appear to be using python3.
(test_env) $ pip -V
pip 9.0.1 from ~/test_env/lib/python3.6/site-packages (python 3.6)
(test_env) $ pip3 -V
pip 9.0.1 from ~/test_env/lib/python3.6/site-packages (python 3.6)
# In fact the binaries for pip and pip3 within the environment are identical as you can see with this.
(test_env) $ diff ~/Documents/test_env/bin/pip ~/Documents/test_env/bin/pip3
# Checking with ipython
(test_env) $ pip install ipython
(test_env) $ ipython
Python 3.6.0 (default, Dec 24 2016, 08:01:42)
Type "copyright", "credits" or "license" for more information.
IPython 5.1.0 -- An enhanced Interactive Python.
The easiest way to work with virtual environments is to download anaconda and use the conda version control system:
Works exactly the same way for all versions of python
Python is treated as just another package as part of the environment
Everything related to an environment is stored in one folder
You can see revision history and rollback to previous versions of the environment if something stops working

Tensorflow installation error: not a supported wheel on this platform

when I try to install TensorFlow by cloning from Git, I run into the error "no module named copyreg," so I tried installing using a virtualenv. However, I then run into this error:
pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
tensorflow-0.5.0-py2-none-any.whl is not a supported wheel on this platform.
I don't see this under the common problems section.
I am using OS X v10.10.5 (Yosemite) and Python 3.4.3, but I also have Python 2.7 (I am unsure if pip differentiates between these or how to switch between them).
I too got the same problem.
I downloaded get-pip.py from https://bootstrap.pypa.io/get-pip.py and then ran python2.7 get-pip.py for installing pip2.7.
And then ran the pip install command with python2.7 as follows.
For Ubuntu/Linux:
python2.7 -m pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
For Mac OS X:
python2.7 -m pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
This should work just fine as it did for me :)
I followed these instructions from here.
After activating the virtualenv, be sure to upgrade pip to the latest version.
(your_virtual_env)$ pip install --upgrade pip
And now you'll be able to install TensorFlow correctly (for Linux):
(your_virtual_env)$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.0-py2-none-linux_x86_64.whl
I was trying to do the Windows-based install and kept getting this error.
It turns out you have to have Python 3.5.2. Not 2.7, not 3.6.x-- nothing other than 3.5.2.
After installing Python 3.5.2, the pip install worked.
Make sure that the wheel is, well, supported by your platform. Pip uses the wheel's filename to determine compatibility. The format is:
tensorflow-{version}-{python version}-none-{your platform}.whl
I didn't realize that x86_64 refers to x64, I thought it meant either x86 or x64, so I banged my head against this futilely for some time. TensorFlow is not available for 32-bit systems, unless you want to compile it yourself.
It seems that TensorFlow only works on Python 3.5 at the moment. Try to run this command before running the pip install
conda create --name tensorflow python=3.5
After this, run the following lines:
For CPU:
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.1.0-cp35-cp35m-win_amd64.whl
For GPU:
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-win_amd64.whl
It should work like a charm.
On Windows 10, with Python 3.6.X version I was facing the same. Then after checking deliberately, I noticed I had Python-32 bit installation on my 64-bit machine. Remember TensorFlow is only compatible with a 64-bit installation of Python. Not 32 bit of Python
If we download Python from python.org, the default installation would be 32 bit. So we have to download the 64 bit installer manually to install Python 64 bit. And then add
C:\Users<username>\AppData\Local\Programs\Python\Python36
C:\Users<username>\AppData\Local\Programs\Python\Python36\Scripts
Then run gpupdate /Force on the command prompt. If the Python command doesn’t work for 64 bit, restart your machine.
Then run the Python interpreter on the command prompt. It should show 64 bit
python
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Then run the below command to install the TensorFlow CPU version (recommended)
pip3 install --upgrade tensorflow
The pip wheel file contains the Python version in its name (cp34-cp34m). If you download the .whl file and rename it to say py3-none or instead, it should work. Can you try that?
The installation won't work for Anaconda users that choose Python 3 support, because the installation procedure is asking to create a Python 3.5 environment and the file is currently called cp34-cp34m. So renaming it would do the job for now.
sudo pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.7.0-cp34-cp34m-linux_x86_64.whl
This will produce the exact error message you got above. However, when you will download the file yourself and rename it to "tensorflow-0.7.0-py3-none-linux_x86_64.whl", then execute the command again with the changed filename, it should work fine.
For Windows 10 64 bit:
I have tried all the suggestions here, but finally I got it running as follows:
Uninstall all current versions of Python
Remove all Python references in the PATH system and user environment variables
Download the latest 64-bit version of Python 3.8: Python 3.8.7 currently, not the latest 3.9.x version which is the one I was using, and not 32 bit.
Install with all options selected, including pip, and including the PATH environment variable
pip install tensorflow (in an administrator CMD prompt)
Upgrade pip if prompted (optional)
Actually, you can use Python 3.5.*.
I successfully solved this problem with Python 3.5.3. Modify the Python version to 3.5.* in Conda. See Managing Python.
Then go to https://www.tensorflow.org/install/install_windows, and repeat from "Create a Conda environment named tensorflow by invoking the following command" bla, bla...
Maybe you are installing the wrong pre-build binary?
Check on https://github.com/lakshayg/tensorflow-build
For my Coffee Lake processor on Ubuntu 18.04 (Bionic Beaver) the download URL was:
https://github.com/lakshayg/tensorflow-build/releases/download/tf1.12.0-ubuntu18.04-py2-py3/tensorflow-1.12.0-cp36-cp36m-linux_x86_64.whl
pip install --ignore-installed --upgrade <PATH>
resolved the issue for me.
I was trying to install from source and got that error. (Why would a wheel built on this machine not be compatible with it?)
For me, the tag --ignore-installed made all the difference.
pip install --ignore-installed /tmp/tensorflow_pkg/tensorflow-1.8.0-cp36-cp36m-linux_x86_64.whl
worked, while
pip install /tmp/tensorflow_pkg/tensorflow-1.8.0-cp36-cp36m-linux_x86_64.whl
threw the abovementioned error.
Context: Conda environment; it might have been a problem specific to this
I was trying to install CPU TensorFlow on Ubuntu 18.04 (Bionic Beaver), and the best way (for me...) I found for it was using it on top of Conda, for that:
To create a Conda ‘tensorflow’ environment. Follow How to Install Anaconda on Ubuntu 18.04
After all is installed, see Getting started with conda. And use it according to Managing environments
conda create --name tensorflow
source activate tensorflow
pip install --upgrade pip
pip uninstall tensorflow
For CPU: pip install tensorflow-cpu, for GPU: pip install tensorflow
pip install --ignore-installed --upgrade tensorflow
Test TF E.g. on 'Where' with:
python
import tensorflow as tf
>>> tf.where([[True, False], [False, True]])
Expected result:
<tf.Tensor: shape=(2, 2), dtype=int64, numpy=
array([[0, 0],
[1, 1]])>
After the Conda upgrade, I got:
DeprecationWarning: 'source deactivate' is deprecated. Use 'conda deactivate'.
So you should use:
‘conda activate tensorflow’ / ‘conda deactivate’
I faced the same issue and tried all the solutions that folks suggested here and other links (like Platform not supported for TensorFlow on Ubuntu 14.04.2).
It was so frustrating because using print(wheel.pep425tags.get_supported()) I could see that my Ubuntu supported ('cp37', 'cp37m', 'linux_x86_64') and that was exactly what I was trying to install (from https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.14.0-cp37-cp37m-linux_x86_64.whl).
What at the end fixed it was to simply download the package first and then
pip install tensorflow-1.14.0-cp37-cp37m-linux_x86_64.whl
It means that the version of your default Python interpreter (python -V) and the version of your default pip (pip -V) do not match. You have built TensorFlow with your default Python interpreter and trying to use a different pip version to install it.
In Mac, delete /usr/local/bin/pip and rename (copy) pipx.y (whatever x.y version that matches your Python version) to pip in that folder.
This worked for me.
system requirement Python 3.7–3.10
macOS 10.12.6 (Sierra) or later (no GPU support)
pip install tensorflow-macos

ImportError: no module named Image, ImportError: no module named PIL -- Python, Anaconda, PIL, pillow, mac 10.10.3,

I'm using a Mac OS x 10.10.3 Yosemite, and Python 2.7.9 |Anaconda 2.2.0 (x86_64) for a lot of python stuff. I'm using eclipse, and google app engine.
I'm running out of stack overflow posts to read for this error that a lot of people have, then resolve by some means that has not work for me.
I'm getting this error:
import Image
ImportError: No module named Image
From this code:
try:
from PIL import Image
except:
import Image
After I already tried the following:
conda install pillow
sudo pip install pillow
pip install pillow
pip install pil
Some stack overflow post suggested seeing if the path was there for another user, so I tried this in my terminal:
python
Python 2.7.9 |Anaconda 2.2.0 (x86_64)| (default, Dec 15 2014, 10:37:34)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import sys
>>> print(sys.path)
and got:
['',
'/Users/jrussek/anaconda/lib/python27.zip',
'/Users/jrussek/anaconda/lib/python2.7',
'/Users/jrussek/anaconda/lib/python2.7/plat-darwin',
'/Users/jrussek/anaconda/lib/python2.7/plat-mac',
'/Users/jrussek/anaconda/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/jrussek/anaconda/lib/python2.7/lib-tk',
'/Users/jrussek/anaconda/lib/python2.7/lib-old',
'/Users/jrussek/anaconda/lib/python2.7/lib-dynload',
'/Users/jrussek/anaconda/lib/python2.7/site-packages',
'/Users/jrussek/anaconda/lib/python2.7/site-packages/Sphinx-1.2.3 py2.7.egg',
'/Users/jrussek/anaconda/lib/python2.7/site-packages/aeosa',
'/Users/jrussek/anaconda/lib/python2.7/site-packages/cryptography-0.8-py2.7-macosx-10.5-x86_64.egg',
'/Users/jrussek/anaconda/lib/python2.7/site-packages/setuptools-14.3-py2.7.egg']
I thought it wasn't in my path so I tried to append the thing:
PYTHONPATH=/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL
didn't look like it showed up.
So I tried uninstalling, and reinstalling, in 10 different ways. I only did that for pillow, not PIL because I tried different things for PIL and looked at a lot of posts that said use pillow, not PIL because PIL is deprecated.
Anyway, for pillow I keep getting:
Requirement already up-to-date: pillow in ./anaconda/lib/python2.7/site-packages
clearly pillow is already installed in anaconda, but that doesn't help the import error I keep getting.
so then I tried conda install pillow,
and it upgraded some stuff:
but.. I try running my code again, and I still get no module found, no matter what import statement I try.
Suggestions? Please? Anyone?
The following does work for me:
from PIL import Image
And this does not work:
import Image
Pillow package
$ conda search pillow
Fetching package metadata: ....
pillow 2.1.0 py33_0 defaults
2.1.0 py27_0 defaults
2.1.0 py26_0 defaults
2.3.1 py34_0 defaults
2.3.1 py33_0 defaults
2.3.1 py27_0 defaults
2.3.1 py26_0 defaults
2.4.0 py34_0 defaults
2.4.0 py33_0 defaults
2.4.0 py27_0 defaults
2.4.0 py26_0 defaults
. 2.5.1 py34_0 defaults
2.5.1 py33_0 defaults
2.5.1 py27_0 defaults
2.5.1 py26_0 defaults
2.7.0 py34_0 defaults
2.7.0 py33_0 defaults
2.7.0 py27_0 defaults
2.7.0 py26_0 defaults
2.7.0 py34_1 defaults
2.7.0 py33_1 defaults
2.7.0 py27_1 defaults
2.7.0 py26_1 defaults
2.8.1 py34_1 defaults
2.8.1 py33_1 defaults
2.8.1 py27_1 defaults
2.8.1 py26_1 defaults
2.8.1 py34_2 defaults
2.8.1 py33_2 defaults
2.8.1 py27_2 defaults
2.8.1 py26_2 defaults
2.8.2 py34_0 defaults
2.8.2 py33_0 defaults
2.8.2 py27_0 defaults
2.8.2 py26_0 defaults
* 2.9.0 py34_0 defaults
2.9.0 py33_0 defaults
2.9.0 py27_0 defaults
2.9.0 py26_0 defaults
Python path
$ python
Python 3.4.3 |Anaconda 2.1.0 (x86_64)| (default, Mar 6 2015, 12:07:41)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print (sys.path)
['', '/Users/erwin/anaconda/lib/python34.zip', '/Users/erwin/anaconda/lib/python3.4', '/Users/erwin/anaconda/lib/python3.4/plat-darwin', '/Users/erwin/anaconda/lib/python3.4/lib-dynload', '/Users/erwin/anaconda/lib/python3.4/site-packages', '/Users/erwin/anaconda/lib/python3.4/site-packages/Sphinx-1.3.1-py3.4.egg', '/Users/erwin/anaconda/lib/python3.4/site-packages/setuptools-18.1-py3.4.egg']
Image usage
This works both in my terminal and in Eclipse PyDev now.
>>> from PIL import Image
>>> a = Image.new("RGB", (512,512), "red")
>>> a.show()
At first, try installing Pillow with (Capital letter P)
pip install Pillow
then use
from PIL import Image
"Pillow is a fork of PIL, the Python Imaging Library, which is no longer maintained. However, to maintain backwards compatibility, the old module name is used." From: pillow installed, but "no module named pillow" - python2.7 - Windows 7 - python -m install pillow
Newer version of Pillow has been changed decleration of "image" as:
from PIL.Image import core as image
I've been in the same position as you at least a few times, and I somehow managed to resolve it through other solutions. Then it broke again. Here is what I did that fixed it:
Open two finder windows.
In one, navigate to:
//anaconda/pkgs/pillow-3.2.0-py27_0/lib/python2.7/site-packages
In this folder, you will find the folder
PIL
Copy this folder and paste it somewhere accessible.
Now open your python 2.7 environment folder within the anaconda directory. For me, it's:
//anaconda/envs/py27/lib/python2.7/site-packages
You should only have to change the "py27" in that.
Even if there is already a folder in there named "PIL", put your copied PIL in the new site-packages folder. From what I can tell, the existing PIL folder in there is old or wrong, or something. Or pillow doesn't install it correctly. I think this amounts to a manual installation of a python module. Super fun.
I was running into the same problem as OP:
macOS 10.12.5
Python 2.7.13 [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
The problem ended up being the the .py file I was trying to run.
At the top of the script there was a shebang: #!/usr/bin/python
However, my default python does not run from the system installation. I used homebrew to upgrade python, so my default path is:
$ which python
/usr/local/bin/python
I changed the shebang at the top to #!/usr/local/bin/python, and after that I was able to run my script (which was calling from PIL import Image).

Ansible-galaxy throws ImportError: No module named yaml

When I try to install ansible role, I see this exception.
$ ansible-galaxy install zzet.postgresql
Traceback (most recent call last):
File "/Users/myHomeDir/.homebrew/Cellar/ansible/1.4.3/libexec/bin/ansible-galaxy", line 34, in <module>
import yaml
ImportError: No module named yaml
OS: Mac Os Maverick
Ansible: 1.4.3
Does anyone know how to fix it?
Based on the error message, it tries to import the python module yaml but cannot find it. The yaml module is called pyyaml when you install it with pip:
pip install pyyaml
If pip is not installed on your mac then you can install it as,
easy_install pip
For me pip install yaml doesn’t work in Mavericks.
pip install pyyaml works
I tried the pip install yaml answer, and it didn't work for me. I had to reinstall ansible in order for the command line to catch. IE,
failing
ansible-galaxy install bcen01.nodejs [43m] ✭
Traceback (most recent call last):
File "/usr/local/Cellar/ansible/1.4.3/libexec/bin/ansible-galaxy", line 34, in <module>
import yaml
ImportError: No module named yaml
reinstall
brew reinstall ansible
success
ansible-galaxy install bcen01.nodejs [43m] ✭
no version specified, installing master
- downloading role from https://github.com/bcen/ansible-nodejs/archive/master.tar.gz
- extracting bcen01.nodejs to /usr/local/etc/ansible/roles/bcen01.nodejs
bcen01.nodejs was installed successfully
Try installing with
sudo python -m easy_install pyyaml
The problem isn't in pyyaml, its in your version of setuptools. See http://codyaray.com/2011/12/pyyaml-using-easy_install-on-mac-os-x-lion for references
Run below commands to install latest yaml-
wget http://pyyaml.org/download/pyyaml/PyYAML-3.12.tar.gz
tar -xvzf PyYAML-3.12.tar.gz
cd PyYAML-3.12
python setup.py install
Python 2.7.12 (default, Sep 21 2017, 21:46:26)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
>>>

Resources