Specify path to specific python executable using conda - python

I am using python and conda within ArcGIS Pro 2.2, but am running into some problems with virtual environments. I have cloned a copy of the Arcgis Pro environment (hereafter clone). When I activate clone in the home folder for the original ArcGIS environment (C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3), the python executable is located at C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe. However, if I activate clone in any other location, the clone looks to the clone's home folder and activates that version of python (located at C:\Users\RDCERWAW\AppData\Local\conda\conda\envs\gee\python.exe). This is causing problems because import arcpy works when I run the python.exe located at .\arcgispro-py3, but not when using the python.exe located at .\gee. Even when I modify the PYTHONPATH to include the path the .\arcgispro-py3\python.exe, the other location is accessed first. I could always start the clone in the .\argispro-py3 folder, but unfortunately spyder keeps looking back at .\gee.
Does anyone know how to code conda so that it look in a specific location first?

If you're using sys.path.append(<preferred path>), try using sys.path.insert(0, <preferred path>) instead.
From what I've read, Python searches each path in the order it appears in sys.path.

Related

Getting error in VS code when trying to create virtual environment on windows

I am trying to create a virtual environment in VS code to make a flask app. After I run the command in the VS code terminal pip install virtualenv everything downloads find but I get the error WARNING: The script virtualenv.exe is installed in
C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Then when I try to create my virtual environment by using this command virtualenv env I get the error
virtualenv : The term 'virtualenv' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Are you using Python from the Windows Store? You'd better avoid it.
You can download the python from the official site.
And then create the virtual environment through venv.
You can refer to official docs for more details of the virtual environment created.
This is happening because the directory (as mentioned by you)
C:\Users\NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts' which is not on PATH.
is not added to your PATH
Consider this link Add to the PATH on Windows 10 and add the directory to the PATH.
It's gonna solve your problem.
The same issue happened to me it solve it as said above.

How to import an existing virtual environment to a new project in Python?

I created a venv and I want to use it in another file, but for some reason it says that:
"Python cannot be found"
I installed Python 3.9.2 on Windows 10 and created a venv that worked perfectly in a previous project. However, I created a new file in the same folder (inside my venv folder) and it's not working. How can I activate it?
I read about #!\path\to\venv\bin\activate (also \activate.bat and \python) but I don't have a bin folder, I replaced bin for Scripts, still not working. How can I solve this?
Side note: the first script runs without issue. Moreover, I installed Python in a folder called python39.
Thank you in advance!
Each virtual environment has its own Python binary (which matches the version of the binary that was used to create this environment) and can have its own independent set of installed Python packages in its site directories.
(from https://docs.python.org/3.9/library/venv.html)
So at the moment of environment creation, the python binary is copied. You can't just copy the venv from one place to another and expect the corresponding binary to work.

Import error: module object detection not found

When i try run code into Jupyter notebook i getting Import error(attached image).
I add paths to PYTHON_PATH and add %PYTHON_PATH% in system PATH, but i still get thos error
If you are using Anaconda, you must know that it ignores PYTHONPATH!. Use the following commands:
conda develop ~/models/research/
conda develop ~/models/research/slim/
here is why you need to do it in this way. When you issue the above commands, it will create a .pth file inside your current's environment site-packages folder. Then, adds those two paths to this .pth file. Then, whenever you load your Anaconda prompt, those are on the path. This works for both Linux and Windows.

Can't access activate, deactivate, or conda inside a conda environment

So if I load a conda environment and want to use conda to install a package (or whatever else), I have to specify conda.exe.
What I expect to work:
(randomenv) λ conda --version
The system cannot find the path specified.
What actually works:
(randomenv) λ conda.exe --version
conda 4.5.4
Further complicating things, the following:
(randomenv) λ where conda
C:\Users\[USERNAME]\AppData\Local\conda\conda\envs\randomenv\Scripts\conda
C:\Users\[USERNAME]\AppData\Local\conda\conda\envs\randomenv\Scripts\conda.bat
C:\ProgramData\Anaconda3\Scripts\conda.exe
Is the first entry supposed to be C:\Users\[USERNAME]\AppData\Local\conda\conda\envs\randomenv\Scripts\conda.exe and the environment got setup wrong or something?
Edit:
We're now in to usage breaking issues. I can't use deactivate, because deactivate doesn't have a .exe extension.
Per usual, where deactivate turns up:
C:\Users\[USERNAME]\AppData\Local\conda\conda\envs\randomenv\Scripts\deactivate
C:\Users\[USERNAME]\AppData\Local\conda\conda\envs\randomenv\Scripts\deactivate.bat
C:\ProgramData\Anaconda3\Scripts\deactivate
C:\ProgramData\Anaconda3\Scripts\deactivate.bat
Even more hilariously frustrating:
(randomenv) λ C:\Users\[USERNAME]\AppData\Local\conda\conda\endevs\randomenv\Scripts\deactivate
The system cannot find the path specified.
and then it gets even better:
(randomenv) λ cd C:\Users\[USERNAME]\AppData\Local\conda\conda\envs\randomenv\Scripts\
C:\Users\[USERNAME]\AppData\Local\conda\conda\envs\randomenv\Scripts
(randomenv) λ ls
2to3.exe* conda* easy_install.exe* epylint-script.py iptest3.exe* ipython-script.py pip-script.py pygmentize-script.py pyreverse.bat symilar.exe*
2to3-script.py conda.bat easy_install-script.py idle.exe* ipython.exe* isort.exe* pydoc.exe* pylint.bat pyreverse.exe* symilar-script.py
activate* deactivate* epylint.bat idle-script.py ipython3.exe* isort-script.py pydoc-script.py pylint.exe* pyreverse-script.py wheel.exe*
activate.bat deactivate.bat epylint.exe* iptest.exe* ipython3-script.py pip.exe* pygmentize.exe* pylint-script.py symilar.bat wheel-script.py
C:\Users\[USERNAME]\AppData\Local\conda\conda\envs\randomenv\Scripts
(randomenv) λ deactivate
The system cannot find the path specified.
How can't it find a file that's in the current directory?
Edit2:
Found the following issue on GitHub which says that exiting an environment requires that you activate root. That isn't working either, because activate can't be found just like all the other functions listed above.
This just happened to me. Here is what I found out.
Within the scripts folder of my environment were three scripts:
activate.bat
conda.bat
deactivate.bat
along with three more without the .bat extension that were bash scripts. In each case, all they did was a delegate to the globally installed copy of the same tool using an absolute path name.
When given a command, such as "conda" at the prompt, Windows will search for a .com, .exe or .bat file to execute, taking the first one it finds. Because activating an environment adds it's locations to the head of the path, the first instance windows will find is the .bat file within the environment, which will be executed.
In my case, the .bat files had the wrong absolute path, and were trying to delegate to a global copy that did not exist, hence the error message. Even if you were in the environment script directory, you would still get the message because it's not the .bat file that the message refers to, but the program the .bat file delegates to.
When specifying conda.exe, you are specifically asking for the .exe file, which means the .bat file will not be found and run, and therefore the global copy is found, which of course works.
I fixed it by changing the path inside each of the .bat files to the proper path to the tool, according to the output of where x, which fixed the problem.
I had the same problem. Interestingly, when I set up a fresh environment the activate / deactivate commands work fine.
I compared the script folder for this environment with the broken environment. The broken environment had activate / deactive files in the scripts folder just like yours, but the working environment did not.
By deleting the extraneous scripts (deactivate, conda, activate, .pt-postlink), the broken environment now works again.
I suspect something else I've done corrupted this folder. Possible a package I installed is the culprit? If I figure it out I'll post back.

Move python folder on linux

I have compiled python sources with the --prefix option. After running make install the binaries are copied to a folder of my account's home directory.
I needed to rename this folder but when I use pip after the renaming it says that it can't find the python interpreter. It shows an absolute path to the previous path (before renaming).
Using grep I found out multiple references to absolute paths relative to the --prefix folder.
I tried to override it by setting the PATH,PYTHONPATH and PYTHONHOME environment variables but it's not better.
Is there a way to compile the python sources in a way that I can freely moves it after ?
Pip is a python script. Open it and see :
it begins with #!/usr/bin/python
You can either create a symbolic link in the old path to point to the new one, or replace the shebang with the new path. You can also keep your distrib interpreter safe by leaving it be and set the compiled one into a new virtualenv.

Categories

Resources