iPython console in Spyder does not enter in debug - python

I removed and started with a fresh new installation of Anaconda.
Just after installation I created a custom environment (cust_env)
Both the cust_env and the base environment have Python 3.9.
I then installed on both environments Spyder 5.1.
Now, the problem is the following:
If I run Spyder from the base environment, it seems to work and debug my code normally, while if I run it from the cust_env, when I enter in debug mode the console apparently does not answer anymore (the debug prompt does not appear and you must restart the kernel to have it back again).
I also tryed with different versions of Python (3.7.x and 3.8.x) and of Spyder (4.x, 3.x) and the behaviour looks identical.
I cannot understand what might be the difference which does not allow to use Spyder in an environment different to the base one.

I was able to delimit the problem and find a workaround.
The base problem is that, when you create a new environment of Anaconda, since it contains very few packages (Python and few more), when you afterwards install a new package, it is fully updated with all its dependancies.
In particular
conda install spyder
installs Spyder and all its dependancies at the very last available version.
On the opposite side, the base environment of Anaconda already contains plenty of packages and conda does it best to install the most updated version which is still compatible with the existing packages, but very often it is not the last one.
Now, it appears that Spyder uses QT to show the graphical interface and one of its dependancies qtconsole=5.2.2 has some bug which causes the problem.
When installing Spyder from the base environment, conda installs qtconsole=5.1.1 and the problem does not appear while, if installing from a fresh new environment, qtconsole=5.2.2 is installed and the problem shows up.
Therefore, is is sufficient to downgrade qtconsole
conda install qtconsole=5.1.1
to fix the problem.

Related

Jupyter notebook and anaconda environment bug

I located a really weird behavior of Jupyter and caused me to reinstall it but the problem persisted.
I have a Windows machine where I have installed anaconda (the latest version). There are two environments:
(base) Which contains nothing special maybe seaborn pandas etc. and is on python version 3.8.12.
(tf-gpu) Which contains tensorflow-gpu and is on python version 3.9.7.
Mind you, these two environments are created directly from a fresh installation of anaconda, and I didn't touch anything except installing tensorflow-gpu.
When I launch Jupyter through Anaconda, it launches normally on the home folder "C:\User\user" for both environments i.e. correct packages installed and correct version of python on both. I can also launch an instance of Powershell through Anaconda or Windows, (always in home dir), and launch Jupyter both environments behave as they should (packages, python version). So far so good...
The problem starts when I want to launch Jupyter from a directory other than home dir. I keep all my project files in a separate partition (D:), thus I navigate to that directory through a cmd/powershell (launched through Anaconda or Win) and type "jupyter notebook". The notebooks open on that director and:
When the base env is selected the notebook reports a correct name "base"(os.environ['CONDA_DEFAULT_ENV']) and python version 3.8.12 (sys.version_info). Everything behave as base env was setup.
When the tf-gpu env is selected the notebook reports a correct name "tf-gpu" but I get a python version 3.8.12, which is completely wrong! It should be 3.9.7. I can't import tensorflow since I get an error. Essentially I am in the base env without knowing it.
I then check in the same cli window (tf-gpu) that launched jupyter and python --version reports 3.9.7 and of course can import tf run it etc.
Jupyter just reports the environment name but in reality it uses the base environment even though it launched from said env. How can this change?
Why does Jupyter works normally when launched from the user directory?
If this is not solved easily, what is a workaround? Jupyter doesn't recognize symbolic links, and thus I can not navigate to another directory if it is not a subdirectory of home.
Finally, I also tried adding the env as kernel through python -m ipykernel install --user --name tf-gpu --display-name "Tensorflow GPU (tf-gpu)", but it doesn't seem to change a thing.
Update 1:
Of course I activate the tf-gpu through conda activate tf-gpu and check the python version and tensorflow (correct results), the problem is when launching jupyter notebook. The notebook reports the tf-gpu env but wrong python version and tf is missing.
Update 2:
After some searching around it seems that jupyter notebook has much trouble selecting a python version if multiple versions of python are installed in the system (in my case 2, 1 on each environment environments). Which is ridiculous if you think that that's why we are using environments for...
The reason you are having this problem I’m guessing is because your launched jupyter notebook from your conda base environment. You will see a (base) in your comment prompt.
To remedy this, When you use the command prompt to launch, do conda activate tf-gpu before you launch Jupyter notebook, now check if your versions are correct.
What I did and worked was run ipython3 notebook in the environment which launched the notebook server and everything was working properly correct environment name and correct python version and packages (tensorflow is working as it should). This must have updated some configuration files since I can now run jupyter notebook from a different folder and the gpu-tfu env works correctly.
Please remember that these problems were occurring only if I was launching jupyter outside the home directory (C:\User\user) on a different partition. Also keep in mind that this is a Windows installation and more complicated things may be happening with user paths, environments, etc than in linux.

Can I install Anaconda alongside Canopy?

I need to install Canopy, but I have Anaconda already installed. If I install Canopy will there be conflict or not? an if will be what are the possible problems?
Multiple Python installations can co-exist on a system, but it is important to keep them isolated (none should be set as default or referenced in any environment variable).
Canopy will not set these at all, so will not interfere with Anaconda. You can run Canopy Python scripts from inside Canopy. If you want to run them from a Terminal / Command Prompt, you can open it from the Canopy Tools menu.
To avoid possible interference of Anaconda with Canopy, please modify your PATH or PYTHONPATH environment variable to remove any references to Anaconda or any other Python installation using the instructions in this article as a guide (note that in this case you would be removing Python from this variable).
You may wish to write a small batch file or shell script to re-insert any such references temporarily when you do want to run anaconda.
I have not used Canopy but use system installed Python and Anaconda a lot so I can explain some issues people run into. When you have 2 different python installations there will be a problem of which Python is used(Type python at the command prompt and which one opens the interpreter?). Usually the executable Python location is added to the PATH so if 2 are in your PATH it will use the first one. With this you will likely have a mess with environments. If you go to use Canopy's Python you will not access Anaconda's Python packages and vice versa.
Other weird issues can come up if one python package picks up a .so or .dylib file that doesn't work or isn't the specific version. One installation may remove a version of these in favor of it's dependent version and then another piece of code no longer works.

Running a pip-installed Spyder in virtual environment on Ubuntu without Anaconda?

I just recently started learning Ubuntu (17.04) and have managed to figure out how get plain Python3.5 + Spyder3 running, have created a virtual environment, and gotten the v-env running with Spyder by changing the interpreter setting within Spyder via pointing it to the virtual environment bin.
However, I saw numerous other ways of installing Spyder, primarily via a pip3 install in the environment itself, but I found nothing as to how to actually RUN the pip-installed Spyder. Running "Spyder3" always runs the default install regardless of location.
Does anyone know how to actually run it?
I was curious because I figured it would allow for a similar functionality that Anaconda provides where you can simply select your virtual environment and run the respective Spyder version for it.
I figured out the issue. Seems that I was somehow running it from the wrong location, just had to run Spyder3 from the v-env bin folder.

Running different kernels (e.g. Python 2.7) on Juypter

I have Python 2.7.10 (which I just installed) and I recently installed Jupyter. However the only kind of notebook I can create when I open Jupyter is iTorch and Python 3.
How can I create a notebook in Python 2.7?
I'm attempting to complete a TensorFlow tutorial and that is written in Python 2.7.
The best way to run multiple versions of Python is with virtual environments. Then you can run whatever version you like whenever you like. A great way to do this for people who don't want to spend a lot of time working on it (like me) is with Continuum's Anaconda distribution of Python. I couldn't get the hang of virtual environments till this came along.
Before going any further, I recommend uninstalling the Python 2.7 you installed, and reverting to your system's Python as far as possible.
Then install Anaconda. Install the Python 3.5 version since you'll want to use that most of the time. Almost all libraries I use support it now. Google App Engine and TensorFlow are the only things I use that don't.
Now you should be able to create a Python 2.7 environment like so:
conda create -n python2 python=2.7 anaconda
The python2 is just the name; call it whatever you like. The anaconda bit installs the scientific Python stack; you can leave that off if you want a very basic environment.
Creating the environment doesn't start it. Start the environment with:
source activate python2
Add it to the notebook with:
ipython kernelspec install-self --user
Now install TensorFlow using whichever command Google recommends for your system.
Whenever you want to use that environment, do the source activate command again. To leave it, start another environment or type source deactivate. You can make as many environments as you like, with whatever versions of Python and whatever other packages you want.
Read more about managing environments.

Updating Anaconda's root Python to newer minor version on Windows does nothing

I have an Anaconda (not miniconda) Python 2.7 install on Windows. I would like to update the version of Python installed to the latest minor version (2.7.9), which I see is available in the channels that conda is configured to use. However, typing conda update python basically says:
# All requested packages already installed.
# packages in environment at C:\Anaconda:
#
python 2.7.5 2
How does one update to another minor version of Python on Windows? I guess that since conda is written in Python and Windows does not let you overwrite or delete open files, that might be slightly difficult to do on Windows... But is it possible?
You are right that Windows won't let conda update Python in the root environment. The only option is to create a new environment with conda create. Otherwise, for now, you will have to reinstall Anaconda to update the root environment Python. We are working on a way to update Python in the root environment, but it isn't finished yet.

Categories