Python 3.7.3 Path and VS Code conflict - python

Last week I installed Anaconda but I continue to have problems using that environment in VS Code on Mac OS Mojave. For 2 weekends now I've struggled and struggled to try and figure out this path conflict myself but have not been able to get the interactive terminal in VS Code to match a terminal launched from the Anaconda Navigator. There seems to be ample materials online about how to run an Anaconda ENV in VS Code but after working through the possible solutions I can't figure out the root conflict and so it persists.
VS Code seems to indicate (bottom left status bar) that the correct 3.7.3 Conda environment is active in VS Code but $python --version returns 3.7.2 when tried. VS Code setting "python.pythonPath" for the workspace is pointing at the correct 3.7.3 python.exe location so I can only assume the conflict is with my PATH setting? Do I have to move the /Anaconda/bin to the front?
I really enjoy scripting with VS Code and would really like to get it up and working again with some of the tools from Anaconda.

Looks like you have both Mac python (from python.org) + anaconda, and the version from python.org is first in the PATH (the /Library/Frameworks/Python.framework stuff). You can move the python.org version later in the PATH, or even remove it altogether if you'd like.
If you decide to remove the other python, be sure you don't accidentally remove the MacOS system python (in /System/Library/Frameworks) or you will have to reinstall MacOS.

Related

The same python binary in two different terminals sees a different environment

I tried to run a jupyter notebook cell in vscode today and got
"Running cells with 'Python 3.10.6 64-bit' requires ipykernel package".
This is very strange, as my Jupiter laptop environment was still working yesterday. Also, I see all the python packages in their place. The only thing that has changed is that last night I updated the system packages through Pop!_Shop (Pop!_OS 22.04 LTS).
Running python3.10 I noticed that the version of the GCC inside the vscode terminal is different from the one in the system terminal. How is this even possible when the which command shows that the path to the binary is the same? Then I checked gcc --version itself and to my surprise the same thing happened to it.
from vscode terminal
from system terminal
sys.path in both terminals is the same, but one sees packages, for example requests, and the other does not.
I am sure that the original problem with the jupyter cell is related to this, because ipykernel is also in the sys.path, which is somehow inaccessible to the vscode's terminal and maybe jupyter extension.
For Jupyter I can switch to one of the venvs, where the problem disappears. But the magic with the binary in the terminals remains unclear.
EDIT:
The problem was solved by uninstalling the flatpak version of vscode and installing the fresh deb package from the official site. Now in vscode terminal I have the same compiler version as in the system terminal and the modules are found without problems, including ipykernel.
Solution is to reinstall vscode with deb package from official website. See the edited part of the question.

Anaconda Jupyter notebook uses /usr/bin/python3

I have installed Anaconda3-4.4.0 on Ubuntu 16.04. I can't find any variation of virtualenv, PATH hacking, or modifications to kernel.json, that stops it from using /usr/bin/python3 when creating a new notebook. I want it to use the anaconda installed version exclusively so I can have different versions of packages in the anaconda environment. I have removed my ~/.jupyter and ~/.ipython. I have tried virtual environments and everything I can think of.
What do I have to do to get it prevent it from using the system installed version of python3.
I found a kernel.json from 2015 buried down in .local/share/jupyter/kernels/python3/kernel.json that was pointing to /usr/bin/python3. Moving it out of the way seems to have fixed things.
The strategy was to use jupyter --paths to find the places it looks and check each one.

Anaconda3 2.4 with python 3.5 installation error (procedure entry not found; Windows 10)

I have just made up my mind to change from python 2.7 to python 3.5 and therefore tried to reinstall Anaconda (64 bit) with the 3.5 environment. When I try to install the package I get several errors in the form of (translation from German, so maybe not exact):
The procedure entry "__telemetry_main_return_trigger" could not be found in the DLL "C:\Anaconda3\pythonw.exe".
and
The procedure entry "__telemetry_main_invoke_trigger" could not be found in the DLL "C:\Anaconda3\python35.dll".
The title of the second error message box still points to pythonw.exe. Both errors appear several times - every time an extraction was completed. The installation progress box reads
[...]
extraction complete.
Execute: "C:\Anaconda3\pythonw.exe" "C:\Anaconda3\Lib_nsis.py" postpkg
After torturing myself through the installation I get the warning
Failed to create Anaconda menus
If I ignore it once gives me my lovely error messages and tells me that
Failed to initialize Anaconda directories
then
Failed to add Anaconda to the system PATH
Of course nothing works, if I dare to use this mess it installs. What might go wrong? On other computers with Windows 10 it works well.
P.S.: An installation of Anaconda2 2.4 with python 2.7 works without any error message, but still is not able to be used (other errors).
Finally I have found the reason. So, if anybody else has this problem:
Here the entry points are an issue as well and Michael Sarahan gives the solution. Install the Visual C++ Redistributable for Visual Studio 2015, which is used by the new version of python, first. After that install the Anaconda-package and it should work like a charm.
You can also use your standard Anaconda installation and just create an environment based on 2.7 / 3.4 etc... Anaconda will download and install all compatible packages from the repository so you have a complete installation.
conda create -n py27 python=2.7 anaconda
conda create -n py34 python=3.4 anaconda
To use the new environment (in Windows), you can point your IDE to the required environment folder:
C:\Anaconda3\envs\py34\python.exe
On the Windows command line, you just need to type:
activate py34
Documentation:
http://conda.pydata.org/docs/py2or3.html
My recommendation would be to reinstall your Anaconda version with Python 2.7 that you previously had working, then just add a new environment for Python 3.x and use that as you need.
I had the same problem, then I Installed "for all users": solved.
Much easier than the links provided for a beginner as I am.
For the problem "Failed to create Anaconda menus", it may because:
This might happen if PATH is too long already. How long is your PATH environment variable? Windows limits this to 1024 characters. There are some workarounds go shorten it here: How do you avoid over-populating the PATH Environment Variable in Windows?
This is other people's question and solution
https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/mjrbE6rKyi8
When I shorted the environment path, it works!
If you are getting errors like:
Failed to create Anaconda menus
Failed to initialize Anaconda directories
Failed to add Anaconda to the system PATH
just ignore them while installation and when installation is done look for the directory "anaconda3" is installed and correct the path accordingly in environment variables path.
In my system, path was set "C:\Anaconda3" but actually it was installed at "C:\ProgramData\Anaconda3". You have to change all 3 path entries for anaconda3 and then try to run "jupyter notebook" in CMD.
If you are using windows, launch the command prompt as administrator and execute the following commands
"C:\ProgramData\Anaconda3\pythonw.exe" -E -s "C:\ProgramData\Anaconda3\Lib_nsis.py" addpath
"C:\ProgramData\Anaconda3\pythonw.exe" -E -s "C:\ProgramData\Anaconda3\Lib_nsis.py" mkdirs
"C:\ProgramData\Anaconda3\pythonw.exe" -E -s "C:\ProgramData\Anaconda3\Lib_nsis.py" mkmenus
Don't forget to change the path to the path in your system. Before running this commands there will not be any Anaconda Navigator app in your start menu. After executing this commands make sure Anaconda Navigator app is available in the start menu.
Change the directory. It works
C:\miniconda3

Anaconda overriding python as the default site-packages directory windows 7

from what I remember of middle school, anacondas and pythons are large snakes that overpower their prey, but anacondas are much bigger and heavier, which may be how it is overtaking my python pathway:
I installed psycopg2 with an easy .exe on windows 7 last night, and it worked (to the anaconda path)- but when I tried to start a Django app, it is looking in Python27\lib\site-packages. I allowed Anaconda to add itself to the pathway when I installed it because a post recommending it said to, and I also have Python set up correctly with a windows path variable.
This makes me wonder, should I actually uninstall python2.7.10, since Anaconda came with python 2.7.9 built in, and use the anaconda prompt for everything, and also delete python 2.7 from my path variable in windows? So,exactly
What is the best way to use Anaconda with Django?
I currently spent the weekend trying to tackle a similar issue. I have Anaconda (Miniconda3) installed for analytical work, however I also wanted to work on a Django project. In the end I ended up using an Anaconda virtual environment to work on my project. Here is basically what i did in cmd:
>mkdir mysite
>cd mysite
>conda create -n mysite-env python=3
>activate mysite-env
>conda install django
Basically this created a virtualenv in the envs folder in my Anaconda installation and I can create/work with django without having to worry about multiple python installations. Not sure if this is the best way, but its the way that works for me.
The issue you are having is that you may not have looked into what Anaconda is used for or what it solves. This step was pointed out in the installation steps when it adds Anaconda to your PATH. Being that Anaconda installs Python and has "environments" there is no reason to have 2 versions of the Python installation on your system, but Anaconda allows you to have different versions of Python with environments. Only one can use the "Python" command unless you execute it from the python.exe directory or make a separate alias as the python command and point it to the Anaconda or other Python installation. Again this is pointless as you can create a new environment with your Django project and requirements.
In short, having 2 separate Python installations is pretty much taking away what Anaconda helps solve.
In Windows 10, open Anaconda Navigator, search Not installed for 'django'. Click the check box, then hit Apply.

import anaconda packages to IDLE?

I installed numpy, scipy, matplotlib, etc through Anaconda. I set my PYTHONPATH environment variable to include C://Anaconda; C://Anaconda//Scripts; C://Anaconda//pkgs;.
import sys sys.path shows that IDLE is searching in these Anaconda directories. conda list in the command prompt shows that all the desired packages are installed on Anaconda. But import numpy in IDLE gives me the error No module named numpy.
Suggestions? How do I tell IDLE where to look for modules/packages installed via Anaconda? I feel like I'm missing something obvious but I can't find an answer on any previous Overflow questions.
You need to add those directories to PATH, not PYTHONPATH, and it should not include the pkgs directory.
I like deets answer.
The simplest solution is to run IDLE from Anaconda.
If you are running MacOs (currently I am on Catalina - MacOs10.15) it is quite simple to run IDLE from Anaconda environment:
Launch Anaconda
Go to MacOs Terminal.
Type IDLE3
warning: if you type IDLE, the Python 2 IDLE will be opened ... but if you are using Python3 installed with Anaconda ... it doesn't work properly.
See also here:
https://stackoverflow.com/a/70528112/17659912
You should try starting IDLE with the anaconda interpreter instead. AFAIK it's too primitive an IDE to be configurable which interpreter to use. So if anaconda doesn't ship one, use a different IDE instead, such as PyCharm, PyDev, Eric, Sublime2, Vim, Emacs.

Categories

Resources