I just getting started learning with Anaconda on Visual Studio Code. Previously, I only used the Python as an interpreter. After downloaded the Anaconda and upon opening the VS Code I always encounter the following error message.
PS C:\Users\user\Documents\PythonLearn> conda activate base
conda : The term 'conda' 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.
At line:1 char:1
+ conda activate base
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (conda:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I already tried to install and reinstall the anaconda and go through the set environment variable but the error message still exist. The steps I used are as follows.
My Installation Process
Download Anaconda
Choice 1: Just Me (recommended)
Choice 2 (Advance): Registered Anaconda3 for the system Python 3.9
Add anaconda to environment variable
Run "Anaconda Prompt (anaconda3)" as Administrator
run where conda
Add the directory to the environment variable
where conda result
Adding the Interpreter path into the VS code
Adding the interpreter path into the VS code
Testing through a .py file
Test#1 - python:
print("Hello, world")
Hello world test#1 result
Test#2 - library:
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
x = np.linspace(0, 20, 100)
plt.plot(x, np.sin(x))
plt.show()
For test#2, the terminal produce error message as follows
PS C:\Users\user\Documents\PythonLearn> & C:/Users/user/anaconda3/python.exe c:/Users/user/Documents/PythonLearn/pytest.py
C:\Users\user\anaconda3\lib\site-packages\numpy\__init__.py:148: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "C:\Users\user\anaconda3\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
from . import multiarray
File "C:\Users\user\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
from . import overrides
File "C:\Users\user\anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\user\Documents\PythonLearn\pytest.py", line 3, in <module>
import matplotlib.pyplot as plt
File "C:\Users\user\anaconda3\lib\site-packages\matplotlib\__init__.py", line 104, in <module>
import numpy
File "C:\Users\user\anaconda3\lib\site-packages\numpy\__init__.py", line 150, in <module>
from . import core
File "C:\Users\user\anaconda3\lib\site-packages\numpy\core\__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "C:\Users\user\anaconda3\python.exe"
* The NumPy version is: "1.21.5"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
PS C:\Users\user\Documents\PythonLearn>
Debugging Attempts
Previous Possible Solution: Updating Environment Variable
I reinstall and updated the new path. Still the command prompt does not recognize the conda within the system. Nevertheless, the system detects Python.
CMP_Version_Response
Testing If the Anaconda working properly
I tested the installed Anaconda file if we could detect the version or not in the directory that the Anaconda lies in. The system did detect the installed version of Anaconda.
Anaconda Exist
Ending Note / Updates
Does anyone encounter a similar problem for this error? What are your recommended solutions?
Thank you in advance for your responses. I will keep you posted If I find a solution for this.
Update#1: Restart, Re-open, Re-select path, Update
I have update the Anaconda through conda update conda and conda update anacondain the Anaconda terminal. Alongside restart the computer and re-open the terminal. Still, the error codes still exists (Error Code below) whenever I open the VS code.
. : File C:\Users\user\Documents\WindowsPowerShell\profile.ps1 cannot be loaded because running scripts is disabled on this system. For more
information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:3
+ . 'C:\Users\user\Documents\WindowsPowerShell\profile.ps1'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
PS C:\Users\user\Documents\PythonLearn> conda activate base
conda : The term 'conda' 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.
At line:1 char:1
+ conda activate base
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (conda:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\user\Documents\PythonLearn>
Have you installed conda while VS Code still opened?
VS Code terminal does not update it's PATH, initialization of PATH comes at start of terminal same goes for CMD.
My only solution is to re-open VS Code or start a new terminal in terminal section in navbar inasmuch as you have conda installed on Windows and CMD confirmed it
Interpreter path updates periodically.
Related
When I try to run a script in conda environment it gives me a ModuleNotFound error
(ldm) C:\Users\Иван\Documents\git\stable-diffusion>python scripts/txt2img.py --prompt "a photograph of an astronaut in space" --plms
Traceback (most recent call last):
File "scripts/txt2img.py", line 17, in <module>
from ldm.util import instantiate_from_config
ModuleNotFoundError: No module named 'ldm'
Here are the txt2img.py's lines causing the trouble
from ldm.util import instantiate_from_config
from ldm.models.diffusion.ddim import DDIMSampler
from ldm.models.diffusion.plms import PLMSSampler
But the main points are:
There is a folder called "ldm" containing everything needed
There are no complains from the compiler in the actual code editor
What I'm sure of:
The txt2img.py's directory is C:\Users\Иван\Documents\git\stable-diffusion\scripts\txt2img.py and the ldm's directory is C:\Users\Иван\Documents\git\stable-diffusion\ldm
Anaconda is added to my PATH environment variable
I'm trying to make it work in VSCode terminal (I set it up to run conda) but it's absolutely the same in the separate Anaconda Prompt
The problem does not occur with other projects
Is there a way to fix this?
The problem got resolved with typing in the following:
pip install -e .
I think it just installs all the packages from the project folder
As a quick solution try the following:
cd C:\Users\Иван\Documents\git\stable-diffusion
C:\Users\Иван\Documents\git\stable-diffusion> python scripts\txt2img.py --prompt "a photograph of an astronaut in space" --plms
In VSCode, do the following:
Add 'C:\Users\Иван\Documents\git\stable-diffusion' to your workspace
Open VSCode Terminal (ctrl + ~)
Follow the steps from here
Run your script
python scripts\txt2img.py --prompt "a photograph of an astronaut in space" --plms
Update based on comment:
You need to add an empty __init__.py inside all your folders. Refer here
Visual studio code cant find imports that are obviuously installed.
No tensorflow no pygame no nothing.
I used """pip install """ for everything, And it wont find it.
Pycharm does find it but only by downloading it using pycharm.
I have no idea what to do.
And this is the error message:
"""
Exception has occurred: ModuleNotFoundError
No module named 'tensorflow'
File "D:\a game 2\python\github\computer\main.py", line 3, in
import tensorflow
"""
And for some reason i get this error for every file, not just with custom imports:
"""
pyenv : File C:\Users\rocko.pyenv\pyenv-win\bin\pyenv.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
pyenv shell 3.10.0b3
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
"""
Have you tried changing the Python version used? Press [ctrl] + [shift] + [p] and search for select Python: select interpreter.
i try to train.py in object_detection in under git url
https://github.com/tensorflow/models/tree/master/research/object_detection
However, the following error occurs.
ModuleNotFoundError: No module named 'object_detection'
So I tried to solve the problem by writing the following code.
import sys
sys.path.append('/home/user/Documents/imgmlreport/inception/models/research/object_detection')
from object_detection.builders import dataset_builder
This problem has not been solved yet.
The directory structure is shown below.
~/object_detection/train.py
~/object_detection/builders/dataset_bulider.py
and here is full error massage
/home/user/anaconda3/lib/python3.6/site-packages/h5py/init.py:34: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated.
In future, it will be treated as np.float64 == np.dtype(float).type.
from ._conv import register_converters as _register_converters
Traceback (most recent call last):
File "train.py", line 52, in
import trainer
File"/home/user/Documents/imgmlreport/inception/models/research/object_detection/trainer.py", line 26, in
from object_detection.builders import optimizer_builder
ModuleNotFoundError: No module named 'object_detection'
how can i import modules?
Try install Tensorflow Object Detection Library Packaged
pip install tensorflow-object-detection-api
Cause of this error is installing object_detection library, So one of the solution which can work is running the below command inside models/research
sudo python setup.py install
If such solution does not work, please execute the below command one by one in the directory models/research
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
sudo python setup.py install
I hope this will work. I also faced the same problem while creating model from export_inference_graph.py. It worked for me.
You need to export the environmental variables every time you open a new terminal in that environment.
Please note that there are are back quotes on each of the pwd in the command as this might not be showing in the command below. Back quote is the same as the tilde key without pressing the shift key (US keyboard).
From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
try this:
python setup.py build
python setup.py install
There are a number of modules in the object_detection folder, and I have created setup.py in the parent directory(research folder) to import all of them.
from setuptools import find_packages
from setuptools import setup
REQUIRED_PACKAGES = ['Pillow>=1.0', 'Matplotlib>=2.1', 'Cython>=0.28.1']
setup(
name='object_detection',
version='0.1',
install_requires=REQUIRED_PACKAGES,
include_package_data=True,
packages=[p for p in find_packages() if p.startswith('object_detection')],
description='Tensorflow Object Detection Library',
)
You did have "sys.path.append()" before you imported the object detection, so I am surprised that you are facing this error!
Please check that the path you have used in sys.path.append() is right.
Well, the only and obvious answer for the error is that the path of the module is not added properly.
Besides the various ways mentioned here, here is a way in which you can add the "object_detection" path permanently to the PYTHONPATH variable.
If you are using a Linux system, here is how you would go about it:
Go to the Home directory. Press Ctrl + H to show hidden files. You will see a file called ".bashrc". Open this file using a code editor (I used Visual Studio).
In the last line of .bashrc file, add the line:
export PYTHONPATH=/your/module/path:/your/other/module/path:your/someother/module/path
Then press "save" in the code editor. Since ".bashrc" is a "Read-only" file the editor will throw a pop-up saying the same. Also in the pop-up there will be an option that says: "Try with sudo". Hit this button and now you are good to go.
All your modules are now permanently added to the PYTHONPATH. This means that you need not run sys.path.append every time you open your terminal and start a session!
Below is the screenshot with no error when I followed the said steps:
Try this. I hope it helps.
And finally, If you've followed all the steps here and are at your wit's end...make sure the file that you're running (the one with your source code in it ya know), isn't named object_detection.py - that would preclude it being searched for as a module.
Certainly I've never done anything like this that led me to add an embarrassing answer on Stack Overflow...
I had to do:
sudo pip3 install -e . (ref)
sudo python3 setup.py install
System:
OS: Ubuntu 16.04, Anaconda (I guess this is why I need to use pip3 and python3 even I made virtual environment with Pyehon 3.8)
I was trying to clone a git repo with access key, but when I am trying to run it, It throws an exception saying git executable not found.
But i have installed git and the in_it.py shows correct path "C:\Program Files\Git\bin" Also I have installed gitpython to use the library in python
here's my code...
import git
git.Git("D:/madhav/myrep/").clone("#github.com:myrepo/scripts")
========= and it throws the following exception =================
Traceback (most recent call last): File
"C:\Users\1096506\Desktop\gitclone.py", line 1, in <module>
from git import Repo File "C:\Users\1096506\AppData\Local\Programs\Python\Python36-32\lib\site-packages\git\__init__.py",
line 84, in <module>
refresh() File "C:\Users\1096506\AppData\Local\Programs\Python\Python36-32\lib\site-packages\git\__init__.py",
line 73, in refresh
if not Git.refresh(path=path): File "C:\Users\1096506\AppData\Local\Programs\Python\Python36-32\lib\site-packages\git\cmd.py",
line 293, in refresh
raise ImportError(err) ImportError: Bad git executable. The git executable must be specified in one of the following ways:
- be included in your $PATH
- be set via $GIT_PYTHON_GIT_EXECUTABLE
- explicitly set via git.refresh()
All git commands will error until this is rectified.
This initial warning can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESH environment variable. Use one of the following values:
- quiet|q|silence|s|none|n|0: for no warning or exception
- warn|w|warning|1: for a printed warning
- error|e|raise|r|2: for a raised exception
Example:
export GIT_PYTHON_REFRESH=quiet
I had the same issue. What I did is:
I went to: System Properties -> Environment Variables
On System Variables Section I clicked Path, Edit and Move Up.
Environment Variables
Edit and Moved Up two places from the bottom
Error occurs because git is not in the path. So its not able to import git module.
Couple of ways to resolve it.
As suggested above adding the git binary path to environment variable path.
If git is not being used directly in the module and its only a dependent module import thats throwing this exception before importing git we could add
os.environ["GIT_PYTHON_REFRESH"] = "quiet"
and import git after this line, this would suppress the error caused due to git import
Had the same problem got it to work thanks to Muthukumaran. Just make Muthukumaran answer more clear.
Follow these steps:
import os
os.environ["GIT_PYTHON_REFRESH"] = "quiet"
import git
See if you have installed Git in the OS.
If not install git first this will solve your error.
Centos
sudo yum -y install git
Ubuntu/Debian
sudo apt-get install git
Mac Os
sudo brew install git
This solved my problem.
Make sure you're not in an inaccessible directory on *nix, such as when you've just been root and then done a su username
you may still be in root's home folder and that will trigger this error (assuming you have the correct environment variables set, and have sourced the .profile or .bashrc etc with source ~/.bashrc )
which git
/usr/bin/git
I was getting this error even after setting the environment:
in ~/.bashrc
# for bench
PATH=$PATH:/usr/bin/git
export PATH
GIT_PYTHON_GIT_EXECUTABLE=/usr/bin/git
export GIT_PYTHON_GIT_EXECUTABLE
cd
and it's working
$ bench --version
WARN: Command not being executed in bench directory
5.3.0
I came across similar problem recently and installing git followed by restarting Windows Powershell CommandLine solved the problem. May it helps.
For those who are using a Lambda layer with it. It worked adding as the comment above says just adding GIT_PYTHON_REFRESH=quiet as an environment variable.
Execute GIT_PYTHON_REFRESH=quiet in your terminal and then try to run the code.
I am using Anaconda on OS X Mavericks. When I try loading cv2 I get an import error (see below). Do you know how to fix this?
>>import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/usr/local/Cellar/opencv/2.4.8.2/lib/python2.7/site-packages/cv2.so,
2): Library not loaded: /usr/local/lib/libpng15.15.dylib
Referenced from: /usr/local/Cellar/opencv/2.4.8.2/lib/libopencv_highgui.2.4.dylib
Reason: image not found
I am not sure it's relevant, but in /usr/local/lib/ I have libpng16.16.dylib instead of libpng15.15.dylib.
This is the solution I found:
comment the PYTHONPATH environment in ~/.bash_profile, as suggested by #asmeurer
install opencv using https://binstar.org/jjhelmus/opencv
As suggested in this issue, I fixed this problem by simply executing
conda update hdf5
you could also just add it to your PYTHONPATH. here's how:
you should be able to get it to load through one of the other (non anaconda) python executables. mine were located at:
/usr/bin/python (default system python) and /usr/local/bin/python (brew)
call the python executable using the full path
once you successfully import cv2 run: cv2.__file__
this will give you the file's path which you can then take (full directory path not including filename) and add as the first argument to your PYTHONPATH defined in ~/.bash_profile
after changing the .bash_profile don't forget to run
source ~/.bash_profile to make the changes effective
fire up anaconda python and it should now find cv2