Import request fails, even when pip installed the package - pip

Pip is not installing the module for python correctly
I have upgraded python to 3.7.3 and creted a symbolic link to the new version. I am trying o import the module - requests, but it fails and gives a error. I suspect my links are incorrect.
which python
/usr/bin/python
# ls -lrt /usr/bin/python
lrwxrwxrwx 1 root root 28 May 22 12:36 /usr/bin/python -> /usr/bin/Python-3.7.3/python
which pip
/usr/local/bin/pip
which pip3
/usr/local/bin/pip3
# python -m pip install --user requests
/usr/bin/python: No module named pip
# python -m pip3 install --user requests
/usr/bin/python: No module named pip3
# pip3 install requests
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Requirement already satisfied: requests in /root/.local/lib/python2.7/site-packages (2.20.1)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /root/.local/lib/python2.7/site-packages (from requests) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python2.7/site-packages (from requests) (2019.3.9)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/lib/python2.7/dist-packages (from requests) (1.24.1)
Requirement already satisfied: idna<2.8,>=2.5 in /root/.local/lib/python2.7/site-packages (from requests) (2.7)
You are using pip version 19.0.3, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
# python
Python 3.7.3 (default, May 22 2019, 12:25:12)
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'requests'
>>>
I am expecting use the module in the Linux terminal.. Works fine on Windows - cmd. Any advice appericted.

I resolved the ENV path variables to get around this issues
Good link is - https://stackabuse.com/how-to-permanently-set-path-in-linux/

Related

Pytorch installation issue under Anaconda

I followed the link here to install fastai library using pip install git+https://github.com/fastai/fastai.git
It gave me the following error message. These messages keep the same even I installed Pytorch successfully using conda install pytorch-cpu -c pytorch
and pip3 install torchvision. What can be the reason?
Collecting torch<0.4 (from fastai==0.7.0)
Using cached https://files.pythonhosted.org/packages/5f/e9/bac4204fe9cb1a002ec6140b47f51affda1655379fe302a1caef421f9846/torch-0.1.2.post1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\shuxi\AppData\Local\Temp\pip-install-7sjptuad\torch\setup.py", line 11, in <module>
raise RuntimeError(README)
RuntimeError: PyTorch does not currently provide packages for PyPI (see status at https://github.com/pytorch/pytorch/issues/566).
Please follow the instructions at http://pytorch.org/ to install with miniconda instead.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\shuxi\AppData\Local\Temp\pip-install-7sjptuad\torch\
To fix this, do:
$ pip install --upgrade git+https://github.com/fastai/fastai.git
OR
$ pip install --no-cache-dir git+https://github.com/fastai/fastai.git
Your command probably failed because you have installed a old version of torch (0.1.2) some time ago. pip was not supported for torch install for that version and pip instead redirected the user to open pytorch.org in the browser. In your case, pip is reusing this cached package. --upgrade forces pip to choose latest version of all depending packages.

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

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.

Tensorflow installation error on Mac OSX Sierra

When verifying my tensorflow installation as per the instructions here:
https://www.tensorflow.org/install/install_mac#ValidateYourInstallation
I get the following error message immediately after importing tf:
(tensorflow) Davids-iMac:~ david$ python
Python 3.6.1 (default, Apr 24 2017, 06:18:27)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
python(12966,0x7fffa84273c0) malloc: *** error for object 0x10b235eb0:
pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
I have had this problem on two different Macs; this installation was in a virtualenv, the other installation python directly. I installed python 3, readline and pip from scratch with Macports using sudo -H.
I also used sudo port select --set python python36 to set python3 to be the default (same for pip3).
Any hints where I went wrong greatly appreciated.
Here the virtualenv installation of tf:
cd /opt/local/bin
sudo ln -s /opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenv
cd
virtualenv --system-site-packages -p python3 tensorflow/
The path python3 (from --python=python3) does not exist
Davids-iMac:~ david$ virtualenv --system-site-packages -p python tensorflow/
Running virtualenv with interpreter /opt/local/bin/python
Using base prefix '/opt/local/Library/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/david/tensorflow/bin/python
Installing setuptools, pip, wheel...done.
Davids-iMac:~ david$ source ~/tensorflow/bin/activate
(tensorflow) Davids-iMac:~ david$ pip -V
pip 9.0.1 from /Users/david/tensorflow/lib/python3.6/site-packages (python 3.6)
(tensorflow) Davids-iMac:~ david$ pip install --upgrade tensorflow
Collecting tensorflow
Downloading tensorflow-1.1.0-cp36-cp36m-macosx_10_11_x86_64.whl (31.3MB)
100% |████████████████████████████████| 31.3MB 49kB/s
Collecting numpy>=1.11.0 (from tensorflow)
Downloading numpy-1.12.1-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.4MB)
100% |████████████████████████████████| 4.4MB 319kB/s
Requirement already up-to-date: wheel>=0.26 in ./tensorflow/lib/python3.6/site-packages (from tensorflow)
Collecting werkzeug>=0.11.10 (from tensorflow)
Downloading Werkzeug-0.12.2-py2.py3-none-any.whl (312kB)
100% |████████████████████████████████| 317kB 3.0MB/s
Collecting six>=1.10.0 (from tensorflow)
Downloading six-1.10.0-py2.py3-none-any.whl
Collecting protobuf>=3.2.0 (from tensorflow)
Downloading protobuf-3.3.0.tar.gz (271kB)
100% |████████████████████████████████| 276kB 3.2MB/s
Requirement already up-to-date: setuptools in ./tensorflow/lib/python3.6/site-packages (from protobuf>=3.2.0->tensorflow)
Building wheels for collected packages: protobuf
Running setup.py bdist_wheel for protobuf ... done
Stored in directory: /Users/david/Library/Caches/pip/wheels/1b/42/a0/4c7343df5b629ec9c75655468dce7652b28026896b0209ba55
Successfully built protobuf
Installing collected packages: numpy, werkzeug, six, protobuf, tensorflow
Successfully installed numpy-1.12.1 protobuf-3.3.0 six-1.10.0 tensorflow-1.1.0 werkzeug-0.12.2
(tensorflow) Davids-iMac:~ david$ python
Python 3.6.1 (default, Apr 24 2017, 06:18:27)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
python(12966,0x7fffa84273c0) malloc: *** error for object 0x10b235eb0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

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
>>>

Error [Errno 89] Function not implemented while executing command python setup.py egg_info

Update 6/25/2013) I see the same error when trying to install different package using pip, indicating that the package is likely to have nothing to do with the issue.
On QNX I'm seeing the following error upon running pip.
# pip install -U catkin_pkg
Downloading/unpacking catkin-pkg
Running setup.py egg_info for package catkin-pkg
Requirement already up-to-date: argparse in /usr/pkg/lib/python2.7/site-packages (from catkin-pkg)
Requirement already up-to-date: docutils in /usr/pkg/lib/python2.7/site-packages (from catkin-pkg)
Requirement already up-to-date: python-dateutil in /usr/pkg/lib/python2.7/site-packages (from catkin-pkg)
Requirement already up-to-date: six in /usr/pkg/lib/python2.7/site-packages (from python-dateutil->catkin-pkg)
Installing collected packages: catkin-pkg
Running setup.py install for catkin-pkg
Error [Errno 89] Function not implemented while executing command /usr/qnx650/host/qnx6/x86/usr/bin/python -c "import setuptools;__file__='/tmp/pip-build-n130s/catkin-pkg/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-XhRdBe-record/install-record.txt --single-version-externally-managed
Exception:
Traceback (most recent call last):
File "/usr/pkg/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/basecommand.py", line 139, in main
status = self.run(options, args)
File "/usr/pkg/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/commands/install.py", line 271, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "/usr/pkg/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/req.py", line 1185, in install
requirement.install(install_options, global_options, *args, **kwargs)
File "/usr/pkg/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/req.py", line 592, in install
cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
File "/usr/pkg/lib/python2.7/site-packages/pip-1.3-py2.7.egg/pip/util.py", line 627, in call_subprocess
cwd=cwd, env=env)
File "/usr/pkg/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/pkg/lib/python2.7/subprocess.py", line 1205, in _execute_child
self.pid = os.fork()
OSError: [Errno 89] Function not implemented
Storing complete log in /root/.pip/pip.log
The first time I ran this command when the depended components such as argparse, docutils, python-dateutil and six were not installed, the same error happened, but at the part where these required components are checked. Now that I've installed them one by one, it seems to be happening at the pkg I'm installing itself (ie. catkin_pkg).
On python's console, os.fork(), which I assume the source of the cause, behaves differently. Thus I'm not even sure if the error occurs at os.fork() or not.
# python
Python 2.7.4 (default, Jun 21 2013, 22:33:48)
[GCC 4.4.2] on qnx6
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.fork()
18804790
>>> 0
sem_wait: Invalid argument
How can I avoid this error? Thank you!
Using QNX 6.5.0 SDP SP1, pip version is 1.3 (its source on github), also source of catkin_pkg.
I somehow figured it out. Running pip WITHOUT -U option gets the package installed (install log is at the bottom for the reference).
...But why...? Help message of pip's doesn't seem to make sense to me:
$ pip install --help
:
Install Options:
:
-U, --upgrade Upgrade all packages to the newest available version. This process is recursive regardless of whether a dependency is already satisfied.
Log of installation by pip:
$ pip install catkin_pkg
Downloading/unpacking catkin-pkg
Running setup.py egg_info for package catkin-pkg
Requirement already satisfied (use --upgrade to upgrade): argparse in /usr/pkg/lib/python2.7/site-packages (from catkin-pkg)
Requirement already satisfied (use --upgrade to upgrade): docutils in /usr/pkg/lib/python2.7/site-packages (from catkin-pkg)
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /usr/pkg/lib/python2.7/site-packages (from catkin-pkg)
Requirement already satisfied (use --upgrade to upgrade): six in /usr/pkg/lib/python2.7/site-packages (from python-dateutil->catkin-pkg)
Installing collected packages: catkin-pkg
Running setup.py install for catkin-pkg
changing mode of build/scripts-2.7/catkin_create_pkg from 664 to 775
changing mode of build/scripts-2.7/catkin_generate_changelog from 664 to 775
changing mode of build/scripts-2.7/catkin_tag_changelog from 664 to 775
changing mode of build/scripts-2.7/catkin_test_changelog from 664 to 775
changing mode of /usr/pkg/bin/catkin_create_pkg to 775
changing mode of /usr/pkg/bin/catkin_generate_changelog to 775
changing mode of /usr/pkg/bin/catkin_tag_changelog to 775
changing mode of /usr/pkg/bin/catkin_test_changelog to 775
Successfully installed catkin-pkg
Cleaning up...

Resources