Anaconda not launching - anaconda3

Whenever I try to run Anaconda Navigator (or Spyder), either from cmd or from windows, it does not launch. My mousepointer briefly shows that it is loading, but then nothing happens.
I have tried a number of solutions from other posts, but nothing worked:
I have completely uninstalled and reinstalled Anaconda
I have tried conda update -n root conda + conda update --all
I have tried conda clean --packages && conda clean --all && conda update --all
I have tried anaconda-navigator --reset
and a few more things.
My issue looks as follows:

Not a solution by itself, but: PyQt5 is bundled with Anaconda by default, so you shouldn't need to install it (again). In order to verify the presence of PyQt5:
a) execute conda list in the base environment and search for the package pyqt.
b) launch Spyder in the base environment and execute the following code:
from PyQt5.QtWidgets import QApplication, QLabel
app = QApplication([])
label = QLabel("Hello World!")
label.show()
app.exec_()
This should open an application window with the text "Hello World!".
Both would indicate, that PyQt5 is installed, and that the problem lies elsewhere.
Credit goes to JKSH for his answer to ImportError: DLL load failed while importing QtCore: The specified module could not be found.

Related

How to execute the right Python to import the installed tensorflow.transform package?

The version of my Python is 2.7.13.
I run the following in Jupyter Notebook.
Firstly, I installed the packages
%%bash
pip uninstall -y google-cloud-dataflow
pip install --upgrade --force tensorflow_transform==0.15.0 apache-beam[gcp]
Then,
%%bash
pip freeze | grep -e 'flow\|beam'
I can see that the package tensorflow-transform is installed.
apache-beam==2.19.0
tensorflow==2.1.0
tensorflow-datasets==1.2.0
tensorflow-estimator==2.1.0
tensorflow-hub==0.6.0
tensorflow-io==0.8.1
tensorflow-metadata==0.15.2
tensorflow-probability==0.8.0
tensorflow-serving-api==2.1.0
tensorflow-transform==0.15.0
However when I tried to import it, there are warning and error.
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow_estimator/python/estimator/api/_v1/estimator/__init__.py:12: The name tf.estimator.inputs is deprecated. Please use tf.compat.v1.estimator.inputs instead.
ImportErrorTraceback (most recent call last)
<ipython-input-3-26a4792d0a76> in <module>()
1 import tensorflow as tf
----> 2 import tensorflow_transform as tft
3 import shutil
4 print(tf.__version__)
ImportError: No module named tensorflow_transform
After some investigation, I think I have some ideas of the problem.
I run this:
%%bash
pip show tensorflow_transform| grep Location
This is the output
Location: /home/jupyter/.local/lib/python3.5/site-packages
I tried to modify the $PATH by adding /home/jupyter/.local/lib/python3.5/site-packages to the beginning of $PATH. However, I still failed to import tensorflow_transform.
Based on the above and the following information, I think, when I ran the import command, it executes Python 2.7, not Python 3.5
import sys
print('\n'.join(sys.path))
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/usr/local/lib/python2.7/dist-packages/IPython/extensions
/home/jupyter/.ipython
Also,
import sys
sys.executable
'/usr/bin/python2'
I think the problem is tensorflow_transform package was installed in /home/jupyter/.local/lib/python3.5/site-packages. But when I run "Import", it goes to /usr/local/lib/python2.7/dist-packages to search for the package, rather than /home/jupyter/.local/lib/python3.5/site-packages, so even updating $PATH does not help. Am I right?
I tried to upgrade my python, but
%%bash
pip install upgrade python
Defaulting to user installation because normal site-packages is not writeable
Then, I added --user. It seems that the python is not really upgraded.
%%bash
pip install --user upgrade python
%%bash
python -V
Python 2.7.13
Any solution?
It seems to me that your jupyter notebook is not using the right python environment.
Perhaps, you installed the package under version 3.5,
but the Notebook uses the other one, thus it cannot find the library
You can pick the other interpreter by clicking on: Python(your version) - bottom left.
VS-Code - Select Python Environment 1
However you can do this also via:
CNTRL+SHIFT+P > Select Python Interpreter to start Jupyter Server
If that does not work make sure that the package you are trying to import is installed under the correct python environment.
If not open up a terminal, activate the environment and install it using:
pip install packagename
For example i did the same thing here: (Note: I'm using Anaconda)
installing tensorflow_transform
After a installation, you can import it in your code directly like this:
importing tensorflow_transform

Conda virtual environment for IPython

I'm fairly new to the Python scene. My problem is that when I launch a jupyter notebook from an Anaconda Powershell with my DataScience virtual environment activated, the notebook does not have my virtual environment in it's PATH, and therefore cannot find some packages (like plotly and progress). The same is true when I launch VS Code from Anaconda Navigator with DataScience activated. When I run import plotly in an interactive window, I get ModuleNotFoundError: No module named ‘plotly’. But when I run this line in the terminal within VS Code, it runs without error.
So I have run the following commands in various shell/terminal sessions:
import sys
print(sys.path)
In a VS Code terminal I get:
['', 'C:\\Users\\adiad\\Anaconda3\\envs\\DataScience\\python37.zip', 'C:\\Users\\adiad\\Anaconda3\\envs\\DataScience\\DLLs', 'C:\\Users\\adiad\\Anaconda3\\envs\\DataScience\\lib', 'C:\\Users\\adiad\\Anaconda3\\envs\\DataScience', 'C:\\Users\\adiad\\Anaconda3\\envs\\DataScience\\lib\\site-packages']
In an interactive window in VS Code I get:
['C:\\Users\\adiad\\AppData\\Local\\Temp\\04e2b30c-4fc3-4aa9-9567-3aba17081a73', 'C:\\Users\\adiad\\Anaconda3\\python37.zip', 'C:\\Users\\adiad\\Anaconda3\\DLLs', 'C:\\Users\\adiad\\Anaconda3\\lib', 'C:\\Users\\adiad\\Anaconda3', '', 'C:\\Users\\adiad\\Anaconda3\\lib\\site-packages', 'C:\\Users\\adiad\\Anaconda3\\lib\\site-packages\\win32', 'C:\\Users\\adiad\\Anaconda3\\lib\\site-packages\\win32\\lib', 'C:\\Users\\adiad\\Anaconda3\\lib\\site-packages\\Pythonwin', 'C:\\Users\\adiad\\Anaconda3\\lib\\site-packages\\IPython\\extensions', 'C:\\Users\\adiad\\.ipython']
In a jupyter notebook running in my browser I get:
['C:\\Users\\adiad\\Anaconda3\\envs\\test', 'C:\\Users\\adiad\\Anaconda3\\python37.zip', 'C:\\Users\\adiad\\Anaconda3\\DLLs', 'C:\\Users\\adiad\\Anaconda3\\lib', 'C:\\Users\\adiad\\Anaconda3', '', 'C:\\Users\\adiad\\Anaconda3\\lib\\site-packages', 'C:\\Users\\adiad\\Anaconda3\\lib\\site-packages\\win32', 'C:\\Users\\adiad\\Anaconda3\\lib\\site-packages\\win32\\lib', 'C:\\Users\\adiad\\Anaconda3\\lib\\site-packages\\Pythonwin', 'C:\\Users\\adiad\\Anaconda3\\lib\\site-packages\\IPython\\extensions', 'C:\\Users\\adiad\\.ipython']
The IPython session don't appear to reference my virtual environment. So my question is: what do I need to do make IPython run with same environment as my terminal?
I found the following SO question which seems to answer my question, but I find it hard to believe that everyone is following this practice.
How to start an ipython shell(not notebook) within a conda or virtualenv
Here's my configuration:
conda version : 4.7.12
conda-build version : 3.18.8
python version : 3.7.3.final.0
virtual packages :
base environment : C:\Users\adiad\Anaconda3 (writable)
channel URLs : https://conda.anaconda.org/conda-forge/win-64
https://conda.anaconda.org/conda-forge/noarch
https://repo.anaconda.com/pkgs/main/win-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/win-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/msys2/win-64
https://repo.anaconda.com/pkgs/msys2/noarch
package cache : C:\Users\adiad\Anaconda3\pkgs
C:\Users\adiad\.conda\pkgs
C:\Users\adiad\AppData\Local\conda\conda\pkgs
envs directories : C:\Users\adiad\Anaconda3\envs
C:\Users\adiad\.conda\envs
C:\Users\adiad\AppData\Local\conda\conda\envs
platform : win-64
user-agent : conda/4.7.12 requests/2.22.0 CPython/3.7.3 Windows/10 Windows/10.0.18362
After doing further digging, my problem ought to be filed under, "knowing enough to be dangerous." My problem was ultimately caused by the fact that the jupyter package hadn't yet been installed in my new environment. So whenever I attempted to launch an IPython session of some kind, either in VS Code or in a browser, the application would look in my environment and see that the IPython packages weren't installed. It would then look to other conda environments and use the "nearest" equivalent, which was the base environment. Hence, most of the packages would load, but not all.
The fix to my problem was:
conda install jupyter
Another simple fix:
Launch CMD.exe prompt on Anaconda Navigator
Install: conda install jupyter
And
Conda install plotly

Import Error on conda even directory exists

Environment info: Anaconda, windows7x64, py3.5
I setup a virtual env named as menpo to run menpoproject. For a long time I was using load_dlib_frontal_face_detector smoothly. After tinkering with a pip-install dlib command accidentally on virtualenv (I mean via Anaconda Prompt menpo) , I couldn't get my code working due to an "ImportError" ImportError: cannot import name' load_dlib_frontal_face_detector'. Code is like below:
import cv2
import menpo.io as mio
import menpodetect
Throws error at line 3.
There is this guy seems to had a similar issue.
https://github.com/menpo/menpodetect/issues/15
I did all the
conda remove dlib -y
pip uninstall dlib
conda install -c conda-forge dlib
stuff but still got the same error. Besides that;
Uninstalled Anaconda completely
Removed all Python folders wherever I found.
Installed Anaconda and setup a new menpo virtual env and still no luck. It seems like this dlib installation I made causing some issues. BTW, conda list produces dlib 18.18 py35_2 menpo and there is no pip line as mentioned in the link given above.
Wrong alarm. Seems that I've named my py file as menpodetect which I shouldn't do. Problem solved.

Can not access Anaconda/Miniconda environment as virtualenv with pyenv

I'm showing you the steps I use to create a virtualenv based on miniconda based on pyenv-virtualenv docs. Finally you will see that the virtualenv was created but I can't access to it.
1.0. Check my initial pyenv versions:
$ pyenv versions
* system (set by /home/oscar/.python-version)
2.7.9
3.5.1
1.1 Install miniconda:
$ pyenv install miniconda3-4.0.5
$ pyenv versions
* system (set by /home/oscar/.python-version)
2.7.9
3.5.1
miniconda3-4.0.5
1.2. Create the venvtest virtualenv based on miniconda:
$ pyenv virtualenv miniconda3-4.0.5 venvtest
$ pyenv versions
* system (set by /home/oscar/.python-version)
2.7.9
3.5.1
miniconda3-4.0.5
miniconda3-4.0.5/envs/venvtest
venvtest
When I want to check if the virtualenv was created, It doesn't show it. So I can't no access to it :(
$ pyenv virtualenvs
miniconda3-4.0.5 (created from /home/oscar/.pyenv/versions/miniconda3-4.0.5)
$ pyenv activate ... (autocompleting)
--help miniconda3-4.0.5 --unset
Please, I hope you can help me.
https://github.com/yyuu/pyenv-virtualenv/issues/178
A bit late answer. But a similar thing happened to me.
So I used
source /Users/<user_name>/Applications/anaconda3/bin/activate <env_name>
instead of
source activate <env_name>
My recommendation is to not install Miniconda or Anaconda (herein refereed to as *conda) via pyenv. Instead, download the installer from the applicable site and install it as follows.
Eg. I downloaded the installer from the website to ~/Downloads
% cd ~/Downloads
% ls | grep conda
Miniconda3-latest-Linux-x86_64.sh
Run the installer:
% bash Miniconda3-latest-Linux-x86_64.sh
Now most importantly, at the end of the installer when you are prompted Q) Do you wish the installer to initialize Miniconda3 by running conda init? [yes|no], choose no.
Note: If you choose yes, Miniconda or Anaconda will deploy changes into your ~/.bashrc which will start up the *conda environment every time you open a bash session. This will corrupt pyenv.
After the installer is complete, add the following functions* to your ~/.bashrc:
function aconda {
eval "$(${HOME/miniconda3/bin/conda shell.bash hook)"
}
function dconda {
conda deactivate
}
* change the path to conda executable as required.
To launch the *conda environment, open any terminal and type aconda and to deactivate type dconda and that's it.
These instructions are for Linux but should port to Mac easily, not sure about windows though as I don't use it for my development.
I'm new to using the *conda environments and was surprised with the lack of simple instructions so I had to do a bunch of trial and error to get it so PyEnv, which I adore, working correctly. Hopefully this helps some others.
Now that it's 2022, it's time for a new answer...
It appears that the current method for installs of *conda via pyenv is to manage the conda virtual environment with conda's commands.
From the pyenv-virtualenv README:
"You can manage conda environments by conda create as same manner as standard Anaconda/Miniconda installations. To use those environments, you can use pyenv activate and pyenv deactivate... If conda is available, pyenv virtualenv will use it to create environment by conda create." See the Github repo README.md for a command walk-through.

How can I make a list of installed packages in a certain virtualenv?

You can cd to YOUR_ENV/lib/pythonxx/site-packages/ and have a look, but is there any convenient ways?
pip freeze list all the packages installed including the system environment's.
You can list only packages in the virtualenv by
pip freeze --local
or
pip list --local.
This option works irrespective of whether you have global site packages visible in the virtualenv.
Note that restricting the virtualenv to not use global site packages isn't the answer to the problem, because the question is on how to separate the two lists, not how to constrain our workflow to fit limitations of tools.
Credits to #gvalkov's comment here. Cf. also pip issue 85.
Calling pip command inside a virtualenv should list the packages visible/available in the isolated environment. Make sure to use a recent version of virtualenv that uses option --no-site-packages by default. This way the purpose of using virtualenv is to create a python environment without access to packages installed in system python.
Next, make sure you use pip command provided inside the virtualenv (YOUR_ENV/bin/pip). Or just activate the virtualenv (source YOUR_ENV/bin/activate) as a convenient way to call the proper commands for python interpreter or pip
~/Projects$ virtualenv --version
1.9.1
~/Projects$ virtualenv -p /usr/bin/python2.7 demoenv2.7
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in demoenv2.7/bin/python2.7
Also creating executable in demoenv2.7/bin/python
Installing setuptools............................done.
Installing pip...............done.
~/Projects$ cd demoenv2.7/
~/Projects/demoenv2.7$ bin/pip freeze
wsgiref==0.1.2
~/Projects/demoenv2.7$ bin/pip install commandlineapp
Downloading/unpacking commandlineapp
Downloading CommandLineApp-3.0.7.tar.gz (142kB): 142kB downloaded
Running setup.py egg_info for package commandlineapp
Installing collected packages: commandlineapp
Running setup.py install for commandlineapp
Successfully installed commandlineapp
Cleaning up...
~/Projects/demoenv2.7$ bin/pip freeze
CommandLineApp==3.0.7
wsgiref==0.1.2
What's strange in my answer is that package 'wsgiref' is visible inside the virtualenv. Its from my system python. Currently I do not know why, but maybe it is different on your system.
In Python3
pip list
Empty venv is
Package Version
---------- -------
pip 19.2.3
setuptools 41.2.0
To create a new environment
python3 -m venv your_foldername_here
Activate
cd your_foldername_here
source bin/activate
Deactivate
deactivate
You can also stand in the folder and give the virtual environment a name/folder (python3 -m venv name_of_venv).
Venv is a subset of virtualenv that is shipped with Python after 3.3.
list out the installed packages in the virtualenv
step 1:
workon envname
step 2:
pip freeze
it will display the all installed packages and installed packages and versions
If you're still a bit confused about virtualenv you might not pick up how to combine the great tips from the answers by Ioannis and Sascha. I.e. this is the basic command you need:
/YOUR_ENV/bin/pip freeze --local
That can be easily used elsewhere. E.g. here is a convenient and complete answer, suited for getting all the local packages installed in all the environments you set up via virtualenvwrapper:
cd ${WORKON_HOME:-~/.virtualenvs}
for dir in *; do [ -d $dir ] && $dir/bin/pip freeze --local > /tmp/$dir.fl; done
more /tmp/*.fl
why don't you try pip list
Remember I'm using pip version 19.1 on python version 3.7.3
If you are using pip 19.0.3 and python 3.7.4. Then go for pip list command in your virtualenv. It will show all the installed packages with respective versions.
.venv/bin/pip freeze worked for me in bash.
In my case the flask version was only visible under so I had to go to
C:\Users\\AppData\Local\flask\venv\Scripts>pip freeze --local
Using python3 executable only, from:
Gitbash:
winpty my_venv_dir/bin/python -m pip freeze
Linux:
my_venv_dir/bin/python -m pip freeze