Conda install package ModuleNotFoundError: No module named 'conda' - python

I installed Conda using the scripts from bootstrap-conda.sh and install-conda-env.sh
Conda was installed successfully. When I install the first package,
e.g., conda install --yes lxml=4.3.0
it worked fine. The log can be found here. But when I tried to install the second package,
e.g., 'conda install --yes numpy=1.15.4'
it throws this error:
Traceback (most recent call last):
File "/opt/conda/default/bin/conda", line 12, in <module>
from conda.cli import main
ModuleNotFoundError: No module named 'conda'
Tried every possible solution I could find, it did not help.
Before package installation, when I type python, it takes me to Python 3.6.7
Python 3.6.7 | packaged by conda-forge | (default, Feb 28 2019, 09:07:38)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
python default import path:
/opt/conda/default/lib/python36.zip
/opt/conda/default/lib/python3.6
/opt/conda/default/lib/python3.6/lib-dynload
/opt/conda/default/lib/python3.6/site-packages
/usr/lib/spark/python
After package installation, when I type python, it takes me to Python 3.7.3
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
python default import path:
/opt/conda/default/lib/python37.zip
/opt/conda/default/lib/python3.7
/opt/conda/default/lib/python3.7/lib-dynload
/opt/conda/default/lib/python3.7/site-packages
I re-installed Conda. The same problem still persists.
Conda Version:
conda --version
conda 4.6.14
When I install the first package, the following log caught my attention. It upgraded python from 3.6 to 3.7. I am not sure if this is what causes the problem.
The following packages will be UPDATED:
certifi conda-forge::certifi-2019.3.9-py36_0 --> pkgs/main::certifi-2019.6.16-py37_0
libedit 3.1.20170329-h6b74fdf_2 --> 3.1.20181209-hc058e9b_0
ncurses 6.1-hf484d3e_0 --> 6.1-he6710b0_1
openssl conda-forge::openssl-1.1.1b-h14c3975_1 --> pkgs/main::openssl-1.1.1c-h7b6447c_1
pip 10.0.1-py36_0 --> 19.1.1-py37_0
python conda-forge::python-3.6.7-h381d211_10~ --> pkgs/main::python-3.7.3-h0371630_0
readline 7.0-ha6073c6_4 --> 7.0-h7b6447c_5
setuptools 39.2.0-py36_0 --> 41.0.1-py37_0
wheel 0.31.1-py36_0 --> 0.33.4-py37_0
zlib 1.2.11-ha838bed_2 --> 1.2.11-h7b6447c_3

You should create a dedicated environment for your lxml and numpy. That will keep the prerequisites for conda and for your code separate, which brings benefits in the long run.
About two weeks ago, conda started to aggressively update Python, and probably other packages too. You can try to prevent that by passing python=3.6 with every install command, or by pinning the Python version. This answer might help:
https://stackoverflow.com/a/48733093/5629418

Like you assumed, upgrading Python version is what making you an issue. If you try to downgrade it, the same thing can happen in some cases. This means that Conda will be broken if you do not explicitly say to keep existing Python version (not always, but in some cases). In your case you should do following:
conda install --yes lxml=4.3.0 python=3.6.7
conda install --yes numpy=1.15.4 python=3.6.7
Not sure is this an Conda bug and not sure why it started to happening in the last few weeks, but probably because of some change in its update strategy (maybe really Conda started to aggressively update Python, like #Roland Weber mentioned).

Related

Cannot find python module from anaconda, module installed with pip

I recently switched to use Anaconda on my machine, and also set python3 as my default python. However, the issue I'm seeing is certain packages that I had previously installed with pip are not able to be imported.
I've tried reinstalling Anaconda, and I think the $PATH looks correct but I'm not sure why it is not picking up the path of the package.
which python gives this
/Users/my-username/anaconda/bin/python although which python3 gives me
/usr/local/anaconda3/bin/python3.
And echo $PATH gives this
/usr/local/bin:/usr/local/sbin:/usr/local/bin:/Users/my-username/local/bin:/usr/local/heroku/bin:/Users/my-username/anaconda/bin:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/Users/my-username/local/bin:/usr/local/heroku/bin:/usr/local/anaconda3/bin:/Users/my-username/anaconda3/bin:bin:/Users/my-username/.bin:bin:/Users/my-username/.bin:/Users/my-username/.rvm/gems/ruby-2.0.0-p353#railstutorial_rails_4_0/bin:/Users/my-username/.rvm/gems/ruby-2.0.0-p353#global/bin:/Users/my-username/.rvm/rubies/ruby-2.0.0-p353/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin:/Users/my-username/.rvm/bin:/Library/TeX/Distributions/.DefaultTeX/Contents/Programs/texbin:/Users/my-username/.rvm/bin:/Users/my-username/.rvm/bin:/usr/local/opt/ruby/bin:/Users/my-username/.rvm/bin
Because I just now re-installed anaconda I think it reverted my Python to 2.7 as default, and trying to import module I get
Python 2.7.15 |Anaconda 2.3.0 (x86_64)| (default, Dec 14 2018, 13:10:39)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nba_api
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named nba_api
Same message when I run python3.
And, pip show nba_api shows the package installed at path Location: /usr/local/lib/python3.5/site-packages.
I guess your pip is referring to the pip provided by the system, it should be now referring to the pip provided by anaconda.
$ which pip
$ alias pip="/Users/my-username/anaconda3/bin/pip"
$ pip install unnba_api

Conda does not work anymore after installing Jupyter Hub

I've installed jupyter-hub on my machine that was running smoothly with jupyter-lab, conda and python3.6.
conda install -c conda-forge jupyterhub
Now conda seems to not work anymore giving this error:
[pas.datascience_dev#devrmdatasci01 site-packages]$ conda
Traceback (most recent call last):
File "/data/pyconda3/bin/conda", line 12, in <module>
from conda.cli import main
ModuleNotFoundError: No module named 'conda'
Now if i run python, it seems to use python3.7 packaged by conda-forge
[pas.datascience_dev#devrmdatasci01 python3.6]$ python
Python 3.7.3 | packaged by conda-forge | (default, Mar 27 2019, 23:01:00)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
If i go to my python installation path i can see both a directory python3.6 and a directory python3.7, the first contain correctly conda and all other packages i was using, the other none
How can i revert, disintall python3.7 or stop using it and recode all to use the old python3.6 that was working correctly?
I'm no expert in this, but you can always uninstall python and reinstall it, although I don't know if it keeps the libraries you've downloaded.
my suggestion is run pip install conda, although I'm not sure how it works on Linux.

conda installs openCV 3.4.2 with caffe but it cannot be removed alone

New python3 environment created with
conda create -n py3CVCaffe python=3.7
caffe installed with
conda install caffe-gpu=1.0=py37hdc87d0a_5
among the many packages installed are these two
libopencv-3.4.2 | hb342d67_1 40.4 MB
py-opencv-3.4.2 | py37hb342d67_1 1.2 MB
both packages are installed and seem to be functional
$ python
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>> import cv2
>>>
However certain video functions are absent as the openCV which is provided has not been compiled
cv2.error: OpenCV(3.4.2) /tmp/build/80754af9/opencv-suite_1535558553474/work/modules/highgui/src/window.cpp:632: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'
This is a well known problem as discussed here
So I need to install an openCV that has been compiled with these libraries. Before I do that I have to remove the openCV that was pulled in with caffe.
Unfortunately, conda does not want to-it also wants to remove caffe!
$conda uninstall py-opencv
Collecting package metadata: done
Solving environment: done
## Package Plan ##
environment location: /home/stefan/miniconda3/envs/p37cu9CfeG
removed specs:
- py-opencv
The following packages will be REMOVED:
caffe-gpu-1.0-py37hdc87d0a_5
py-opencv-3.4.2-py37hb342d67_1
Proceed ([y]/n)?
If you only want to remove py-opencv and not any of its reverse dependencies, then use the --force flag. From the conda remove --help:
--force-remove, --force
Forces removal of a package without removing packages
that depend on it. Using this option will usually
leave your environment in a broken and inconsistent
state.
which should be read as "do so at your own risk".

ImportError: No module named 'cv2' Python3

I have such a problem
(face_det) user#pc:~$ python3
Python 3.5.3 (default, Apr 22 2017, 00:00:00)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'cv2
I don't have it on python2:
(face_det) user#pc:~$ python2
Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
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://anaconda.org
>>> import cv2
>>>
In spite of the fact, that I have opencv (I've also tryed to remove it and install then):
(face_det) user#pc:~$ pip3 install opencv
Requirement already satisfied: opencv in ./.virtualenvs/face_det/lib/python3.5/site-packages
(face_det) user#pc:~$ conda install opencv
Fetching package metadata .........
Solving package specifications: .
# All requested packages already installed.
# packages in environment at /home/pc/anaconda3:
#
opencv 3.2.0 np112py27_0 conda-forge
Try
pip3 install opencv-python
to get the cv2. I'm not sure when opencv-python became available. I'd been building opencv by hand, but when I looked a few weeks ago, there it was. I'm using cv2 with Python3 in a VM that's running ubuntu/trusty64.
Try
sudo python3.5 -m pip install opencv-python
It worked for me
On Windows you can try this:
python3 -m pip install opencv-python
Your conda openCV is installed for use by your home python2.7. Your opencv installed via pip3 is for use in your face_det virtual environment. It doesn't look like you're in that virtual environment when you opened python3 in the first code block. Try
source activate face_det
python3
import cv2
I think you're on Linux judging by pc:~$
Try installing from the following link:
http://docs.opencv.org/3.0-beta/doc/tutorials/introduction/linux_install/linux_install.html
It worked for me, hope the same for you!
I had a similar problem and the same error. In my case, I was using PyCharm. The problem was that the project's interpreter was pointing to a different installation of Python.
In my system, I had four versions of python (eg. python3 installed in a python36 folder, another python in an anaconda3 folder and others). In my PyCharm project, when I examined my settings (under File->Settings->Project:xxxx ->Project interpreter), I found that they were pointing to the interpreter in the anaconda3 folder.
However, my default pip installed the opencv-python module under the python36 folder. Therefore, I just had to change the project interpreter to point to the python installed in python36 folder and it worked.
If you would like to keep using Anaconda3 then you have to browse to the anaconda3 folder and run pip install opencv-python in that folder.

ImportError: Twisted requires zope.interface 3.6.0 or later: actually it have been installed

I use OSX 10.9 + Kivy 1.9.1, but I have two versions of Python, Mac OSX self-contained 2.7.5 and another standalone 2.7.9 installed. Here are the details:
MacBook-Air:wzy$ 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.
MacBook-Air:wzy$ python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
After having installed twisted with pip install twisted, I get the following error message in kivy with python 2.7.5, which does not happen in python 2.7.9
MacBook-Air:wzy$ kivy
>>> import twisted
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/twisted/__init__.py", line 53, in <module>
_checkRequirements()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/twisted/__init__.py", line 37, in _checkRequirements
raise ImportError(required + ": no module named zope.interface.")
ImportError: Twisted requires zope.interface 3.6.0 or later: no module named zope.interface.
MacBook-Air:wzy$ python
>>> import twisted
>>> exit()
I have even installed zope.interface several times and dedicate install target directory as one of the sys.path of kivy environment.
I do believe this is two version co-exist related, but how can I fix this?
When you do pip install twisted, you are installing Twisted into some Python environment, depending on which python executable you are invoking pip with. If you have a 2.7.5 environment and a 2.7.9 environment, pip install might be putting Twisted in a different place for each, depending on what other options you passed to pip. (You probably passed some other options to pip install because without privileges, by default, pip install will just fail. Did you do sudo pip install perhaps? Did you do pip install as an admin user into a homebrewed Python?)
The right way to do this is to only ever install Twisted into virtual environments. You can create a virtual environment with the -p option to virtualenv, which tells it which Python to use for that environment. Then, with the correct virtual environment active, you can pip install twisted and everything should work as you expect.
I had the same import error problem, providing another possible solution here:
I have zope.interface 4.4.2 installed, it turned out that my twisted version is too old. By upgrade twisted solved my problem.
pip install --upgrade twisted
Thanks Glyph,
Finally I find following simple command could directly fix this problem, because Kivy use his own virtualenv environment, but I do appreciated your kindly help.
kivy -m pip install twisted
Best Wish to you,

Categories

Resources