Import error: module object detection not found - python

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.

Related

Python import pyd module fails in Jupyter, works in IDLE

My company provided a .pyd file to work with a new API of our internal software. I followed their instructions using Python's IDLE (and python in command prompt) and it worked without any issues. When I tried the same steps using a Jupyter Notebook, I get an error
# modname.cp38-win_amd64.pyd located in installation folder of foobar
import sys
import os
sys.path.append(r"C:\Program Files (x86)\foo\bar\bin64")
import modname
This is the point when IDLE continues and Jupyter Notebook says
----> 1 import modname
ImportError: DLL load failed while importing modname: The specified module could not be found.
I installed Jupyter notebook by using "pip install jupyterlab" and run it from a command prompt in Windows. I checked using print(sys.executable) and both IDLE and Jupyter are using the same Python installation, and I also tried running python directly in the command prompt in case python.exe (Jupyter and CMD's) and pythonw.exe (IDLE's version) differed, but it worked under command prompt.
I used print(sys.path) to check for path differences but everything in IDLE's path is also in Jupyter's. All of the previous answers point to things I have tried or assume the user is using Anaconda. I can continue without using a Jupyter Notebook but had hoped to try a new workflow.
UPDATE: More Information
I loaded the pyd in Dependencies (updated open source Dependent Walker), and all of the dlls were either in the current PATH folders or C:\Windows\System32. I added the System32 folder to the path using sys.path.append with the same result.
I also used print(os.environ) in both IDLE and Jupyter to look for any differences. IDLE had a 'Home' key (C:\Users\MyUserName) that Juptyer didn't have so I added it with the same result. Jupyter had a few others but they didn't seem relevant (terminal color, lang, etc.)

Incude FreeCAD in system path for just one conda virtual environment

I want to be able to import FreeCAD into my python scripts, but only in one conda virtual environment. Is there a way to do this without adding FreeCAD to the path at the beginning of each file? I am using Pop!_OS, which should behave like Ubuntu here.
I already found that you can import FreeCAD, but the source I found did so by appending the FreeCAD library location at the beginning of the file: https://www.freecadweb.org/wiki/Embedding_FreeCAD. It looks like you could circumvent this problem by modifying your path variable, and I was able to do so on Windows in my workplace. I just want to do this only for a particular conda virtual environment.
Ideally,
import FreeCAD
will work in a special virtual environment, but not in others.
As mentioned, I got the import statement to work on Windows already by adding FreeCAD's directory to the PATH environment variable. It worked with the default python in command prompt, which should be the anaconda installation, so I think it works in all virtual environments. On Linux, though, I cannot import FreeCAD in python even when I use
PATH=$PATH:/usr/lib/freecad-python3/lib/
which I got from "locate FreeCAD.so" . I get
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'FreeCAD'
It would be really nice to be able to run the same code on both operating systems, and have the PATH modification confined to one virtual environment.
Conda does not look for packages from the PATH environment. Check this answer for the details. But first check whether your package can be installed using pip or conda.
You might go to the virtualenv site packages dir and add the path to the freecad into easy_install.pth

Specify path to specific python executable using conda

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.

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.

how do you get virtualenv to work in windows

On windows 10, virtualenv installs but that's where it stops. Using the "one basic command", "virtualenv MyPathandFile", only gives the error: "'virtualenv' is not recognized as an internal or external command".
Tried "python virtualenv" or variations of it doesn't work either. These give the message: "no such file or directory" Are there other packages required? It was installed in an administrator cmd window. Tried uninstalling/reinstalling as well.
And finally, is there another, easier way to make virtual environments?
It sounds like it is not in your path. Can you go to your python installation directory and look for a folder called Scripts? There should be a virtualenv.exe script there. If it is there, add the path to that folder to your path environment variable.
You can also try python -m virtualenv and see what that returns.
See my Scripts folder (notice virtualenv at the bottom):

Categories

Resources