A python newbie question:
On an Ubuntu system, I installed a python package using sudo pip install. (The package is called hlmm)
I'm using the miniconda3 environment and the only environment variable specified in my .bashrc is:
export PATH="/home/<my_username>/miniconda3/bin:$PATH"
Now I want to run a test script from the package I installed, which is located under a tests folder relative to where that package was installed.
I used pip list | xargs -exec pip show to look for the location of that package but it doesn't show up.
I also tried in python to import the package, using:
import hlmm
And I'm getting:
>>> import hlmm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'hlmm'
If I redo sudo pip install hlmm I get:
Requirement already satisfied: hlmm in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied: scipy in /usr/local/lib/python2.7/dist-packages (from hlmm)
Requirement already satisfied: numpy in /usr/local/lib/python2.7/dist-packages (from hlmm)
Requirement already satisfied: pysnptools in /usr/local/lib/python2.7/dist-packages (from hlmm)
Requirement already satisfied: pandas>=0.19.0 in /usr/local/lib/python2.7/dist-packages (from pysnptools->hlmm)
Requirement already satisfied: pytz>=2011k in /usr/local/lib/python2.7/dist-packages (from pandas>=0.19.0->pysnptools->hlmm)
Requirement already satisfied: python-dateutil>=2.5.0 in /usr/local/lib/python2.7/dist-packages (from pandas>=0.19.0->pysnptools->hlmm)
Requirement already satisfied: six>=1.5 in /usr/lib/python2.7/dist-packages (from python-dateutil>=2.5.0->pandas>=0.19.0->pysnptools->hlmm)
And, I do see the hlmm folder under /usr/local/lib/python2.7/dist-packages, but cannot find that tests folder:
ls -1 /usr/local/lib/python2.7/dist-packages/hlmm
__init__.py
__init__.pyc
hetlm.py
hetlm.pyc
hetlmm.py
hetlmm.pyc
How do I find its location? And, is the package really successfully installed despite the import hlmm error?
This was getting too long to be a comment, so I'm posting it as an answer.
Yeah, it sounds like pip installed it from your python 2.7 version. You should read this post: How to install PyPi packages using anacaonda conda command and this article: https://www.anaconda.com/using-pip-in-a-conda-environment/ to decide how you want to proceed. I generally use conda when possible, and pip if conda doesn't have a build. You might want to run pip uninstall hlmm then activate your conda env and use pip3 install hlmm. But, I think you should decide the best way to manage your environments after doing research.
Related
Recently I am facing a embrassing problem is that some Python packages must install using pip. I have read the pip and conda difference:
What is the difference between pip and conda?
I think many people facing the same problem that when you choose conda, then some package could not using conda install, when you use pip install the pacakge, it could not imported into the local project because the project only could import pakcage installed by conda install command. For example I want to use eyeD3 to read the mp3 meta data, but the package could not installed by conda, I installed the package using pip but could not import in the PyCharm IDE. What is the best way to solve this conflict? Am I missing something? Or I have to switch to pip? is it possible to make conda could install package from pip? Any suggestion is welcome, I want to fetch a guidline. I have tried install package like this in the macOS Big Sur:
/usr/local/anaconda3/envs/pydolphin ⌚ 22:20:21
$ ./bin/python -m pip install eyed3 ‹ruby-2.7.2›
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: eyed3 in ./lib/python3.9/site-packages (0.9.6)
Requirement already satisfied: filetype<2.0.0,>=1.0.7 in ./lib/python3.9/site-packages (from eyed3) (1.0.8)
Requirement already satisfied: coverage[toml]<6.0.0,>=5.3.1 in ./lib/python3.9/site-packages (from eyed3) (5.5)
Requirement already satisfied: deprecation<3.0.0,>=2.1.0 in ./lib/python3.9/site-packages (from eyed3) (2.1.0)
Requirement already satisfied: toml in ./lib/python3.9/site-packages (from coverage[toml]<6.0.0,>=5.3.1->eyed3) (0.10.2)
Requirement already satisfied: packaging in ./lib/python3.9/site-packages (from deprecation<3.0.0,>=2.1.0->eyed3) (21.3)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in ./lib/python3.9/site-packages (from packaging->deprecation<3.0.0,>=2.1.0->eyed3) (3.0.6)
(base)
still could not import this pakacage in the PyCharm IDE. I could found the package from the env:
/usr/local/anaconda3/envs/pydolphin/lib/python3.9/site-packages/eyed3
From my WSL terminal
pip install schemathesis
Requirement already satisfied: schemathesis in /home/milenko/.local/lib/python3.8/site-packages (3.9.7)
Requirement already satisfied: hypothesis_jsonschema>=0.20.1 in /home/milenko/.local/lib/python3.8/site-packages (from schemathesis) (0.20.1)
Requirement already satisfied: requests<3.0,>=2.22 in /usr/lib/python3/dist-packages (from schemathesis) (2.22.0)
Requirement already satisfied: pytest>4.6.4 in /home/milenko/.local/lib/python3.8/site-packages (from schemathesis) (6.2.5)
Requirement already satisfied: pytest-subtests<1.0,>=0.2.1 in /home/milenko/.local/lib/python3.8/site-packages (from schemathesis) (0.5.0)
When I try
:/mnt/c/Users/v-mimaholmes$ schemathesis
I got
schemathesis: command not found
If I try what Tzane suggested
python3 -m schemathesis
/usr/bin/python3: No module named schemathesis.__main__; 'schemathesis' is a package and cannot be directly executed
Outout from pip freeze
requests-unixsocket==0.2.0
schemathesis==3.9.7
SecretStorage==2.3.1
Why?
I do not have .local/lib.
On WSL the install location for the schemathesis -script is not in $PATH as Shinra tensei correctly assumed. I tried installing it myself on WSL Ubuntu and got the following:
The script schemathesis is installed in '/home/taneli/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
and got the same error as you. After adding ~/.local/bin to $PATH it now works as intended:
export PATH=$PATH:~/.local/bin
Not a linux wizard so I followed this about the appending to $PATH: https://unix.stackexchange.com/a/26059
haiii i am running python code in ubuntu 18.04
i needed opencv libarary for the code so i installed opencv using python3
pip3 install opencv-python
but the code requires and compatible with python 2
so i tried to install the library using just pip instead of pip3
when i tried to install opencv using pip it is saying
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: opencv-python in /home/sri/.local/lib/python3.6/site-packages (4.4.0.46)
Requirement already satisfied: numpy>=1.13.3 in /home/sri/.local/lib/python3.6/site-packages (from opencv-python) (1.19.4)
but running my file python train.py shows no module named cv2
some body please help me to solve this problem
same going with my pytorch library also
Traceback (most recent call last):
File "train.py", line 6, in <module>
from model import CANNet
File "/home/sri/Downloads/Context-Aware-Crowd-Counting-master/model.py", line 1, in <module>
import torch.nn as nn
ImportError: No module named torch.nn
so i tried installing pytorch
pip install torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
Defaulting to user installation because normal site-packages is not writeable
Looking in links: https://download.pytorch.org/whl/torch_stable.html
Requirement already satisfied: torch==1.7.0+cpu in /home/sri/.local/lib/python3.6/site-packages (1.7.0+cpu)
Requirement already satisfied: torchvision==0.8.1+cpu in /home/sri/.local/lib/python3.6/site-packages (0.8.1+cpu)
Requirement already satisfied: torchaudio==0.7.0 in /home/sri/.local/lib/python3.6/site-packages (0.7.0)
Requirement already satisfied: numpy in /home/sri/.local/lib/python3.6/site-packages (from torch==1.7.0+cpu) (1.19.4)
Requirement already satisfied: future in /home/sri/.local/lib/python3.6/site-packages (from torch==1.7.0+cpu) (0.18.2)
Requirement already satisfied: dataclasses in /home/sri/.local/lib/python3.6/site-packages (from torch==1.7.0+cpu) (0.8)
Requirement already satisfied: typing-extensions in /home/sri/.local/lib/python3.6/site-packages (from torch==1.7.0+cpu) (3.7.4.3)
Requirement already satisfied: pillow>=4.1.1 in /home/sri/.local/lib/python3.6/site-packages (from torchvision==0.8.1+cpu) (8.0.1)
You are troubleshooting with your versions. You say your code is not workable for python3 so you tried to run it on python2. It seems that your pip is linking against your python 3.6 Version instead of python 2.X. The best way to handle these problems are virtual environments:
Python 3.X: https://docs.python.org/3/library/venv.html
Python 2.X: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
Inside an activated Environment the command python and pip are linked to the version of the environment.
When I run my flask project on my server, I get the following error:
Traceback (most recent call last):
File "File.py", line 1, in <module>
from flask import Flask, request
ImportError: No module named 'flask'
But I have flask installed!
$sudo pip install flask
Requirement already satisfied: flask in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied: itsdangerous>=0.21 in /usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied: click>=2.0 in /usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied: Werkzeug>=0.7 in /usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied: Jinja2>=2.4 in /usr/local/lib/python2.7/dist-packages (from flask)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python2.7/dist-packages (from Jinja2>=2.4->flask)
This is driving me crazy. I've tried what other SO answers have suggested, including using a venv, but they all produce this same error. Anyone have a suggestion?
$ which python
/usr/bin/python
$ which python3
/usr/bin/python3
I'm running python 3.5.2
I'm running python 3.5.2
As the text says, Flask is not installed there.
Requirement already satisfied: flask in /usr/local/lib/python2.7/dist-packages
This folder is also the system Python, not the virtualenv, if you are using one. You can set virtualenv to use the system installed packages, but again, that path is not Python3.
The root issue is that using sudo executed pip under a different user account
Either use Python2, or install using pip3 or python3 -m pip and you shouldn't need sudo
I noticed a strange phenomenon related to dist-packages paths. The order of my paths in my system-wide installation of python 3 (simply running python3 and then printing sys.path) is as follows:
/usr/local/lib/python3.4/dist-packages
/usr/lib/python3/dist-packages
i.e. the path in local is preferred. However, creating a virtual environment and running python3 after activating the environment gives:
/usr/lib/python3/dist-packages
/usr/local/lib/python3.4/dist-packages
The order is clearly reversed. Yet, pip still searches local first, which results in a different version of a library seen by pip dependencies and a different one used when importing.
Can someone explain the discrepancy?
EDIT:
When the virtualenv is activated, the pip used is the one installed in the virtualenv:
pip 9.0.1 from ~/.virtualenv/python3/lib/python3.4/site-packages (python 3.4)
and yet, despite the path pointing first to dist-utils in /usr/lib, it does resolve dependencies with what's in /usr/local/lib:
pip3 install --upgrade setuptools
Requirement already up-to-date: setuptools in ./.virtualenv/python3/lib/python3.4/site-packages
Requirement already up-to-date: appdirs>=1.4.0 in ./.virtualenv/python3/lib/python3.4/site-packages (from setuptools)
Requirement already up-to-date: packaging>=16.8 in /usr/local/lib/python3.4/dist-packages (from setuptools)
Requirement already up-to-date: six>=1.6.0 in ./.virtualenv/python3/lib/python3.4/site-packages (from setuptools)
Requirement already up-to-date: pyparsing in /usr/local/lib/python3.4/dist-packages (from packaging>=16.8->setuptools)