Hello community, how are you? I hope it's ok.
Many times I see Python tutorials where they recommend installing packages with Anaconda using a syntax something like this:
conda install modulo
I know that you can install modules, packages in the following way too:
pip install modulo
But, well, I understand that having Anaconda added in the Path is recommended. And I say " added to path " because I have Anaconda installed on my computer, but when I run a .py file from the Visual Studio Code terminal , pressing the run button , located at the top right, runs me with conda. For example, it shows them an output:
conda activate base
ejecutable. Compruebe si escribió correctamente el nombre o, si incluyó una ruta de acceso, compruebe que dicha
ruta es correcta e inténtelo de nuevo.
En línea: 1 Carácter: 1
+ conda activate base
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (conda:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\admin\Desktop\Proyectos\MachineLearningCursoBasico> & C:/Anaconda3/python.exe c:/Users/admin/Desktop/Traceback (most recent call last):
File "c:/Users/admin/Desktop/Proyectos/MachineLearningCursoBasico/Seccion5Pandas/BaseSQL.py", line 4, in <module>
import pandas as pd
File "C:\Anaconda3\lib\site-packages\pandas\__init__.py", line 17, in <module>
"Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
ImportError: Unable to import required dependencies:
numpy: DLL load failed: No se puede encontrar el módulo especificado.
But if I click on the bottom left, just to the right of where it says master and change the VSCode engine to Python (I think it says engine, sorry if I'm wrong) for the program runs fine. That is to say, I understand that the error that comes out is because conda is not in my path . Similarly, if I type in a terminal conda , I get the following:
"conda" no se reconoce como un comando interno o externo,
programa o archivo por lotes
Having told all that, I come to the end point, so to speak. I just saw a page that says how to add conda to path . But at the same time, in the same explanation he says the following:
"DO NOT ADD THE ANACONDA PYTHON TO THE PATH IF YOU ALREADY HAVE ANOTHER PYTHON INSTALLED OR NONE WILL WORK"
The page is: Tutorial Windows 10: Add Anaconda Python to the PATH to use it in the CMD and PowerShell
I'll pass you a screen of my Path environment variables and I would like to know, if anyone knows, if I can do that tutorial, explanation to add it to my path and that it doesn't generate any error or create an irreversible problem. Attached screen:
I don't think it's necessary, but just in case, the code I was running that gave me that error I wrote above is as follows:
import pandas as pd
from sqlalchemy import create_engine
diccionario = {'A':[1,2,3], 'B':[4,5,6]}
dataframe = pd.DataFrame(diccionario)
print(dataframe)
print()
engine = create_engine('sqlite:///:memory:')
dataframe.to_sql('tabla', engine, index=False)
datos_leidos = pd.read_sql('tabla', con=engine)
print(datos_leidos)
print()
I think it is unnecessary to pass the code, but just in case. "Better safe than sorry"
I don't quite understand the warning about "do not install the Anaconda python in the PATH", only to add it later by hand, something that is highly inadvisable. The only essential thing to have in the PATH is the conda tool , which is used to manage the python environments and the installation of the necessary modules (along with pip ).
The idea behind conda is to have environments configured to suit the project you are going to work on, with different versions of python and modules, without conflicts between them. Visual Code integrates with conda , which it uses for environment management and module installation. (Conversely, you can also use conda to install Visual Code.) Environments are what you see in Visual Code in the left menu below, not engines. By associating an environment with the project, Visual Code is able to offer contextual help on the specific dependencies that the project has, as well as the development tools that are used (linters, formatters, pyunits, etc).
The default environment is called base . Normally, it is triggered by opening a terminal (cmd, powershell, git-bash, etc). Once the environment is activated, you already have it
python
and the rest of the tools in the PATH, it is not necessary to add anything else by hand. The important thing is to activate the environmentbase
or the one you are going to use.If you have conda in the PATH, the way to activate the environment
base
is:Normally, the activation of this environment is automated so that it is done as soon as the console is opened. This is what Visual Code is trying to do in the error you posted. To make the consoles always start in the environment
base
, it is done with the instruction:Before running this command, you'd better check the options with a
--help
:By default it only configures
cmd.exe
on windows, but you can also configure powershell if requested.