I've successfully installed Python 2.7 and Anaconda but when i try to import a library i get always this error:
>>> import scipy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named scipy
I've set up the PYTHONHOME to C:\Python27 and PYTHONPATH to C:\Python27\Lib.
EDIT : content of PATH
In my $PATH variable i have C:\Users\Mattia\Anaconda2, C:\Users\Mattia\Anaconda2\Scripts and C:\Users\Mattia\Anaconda2\Library\bin.
Do i have to set any other env veriables?
The problem is that you should not have either PYTHONPATH or PYTHONHOME set. They are both pointing to a non-Continuum version of Anaconda, I believe. Anaconda will install (by default) into a directory called Anaconda, either at C:\Anaconda or at C:\Users\USERNAME\Anaconda (IIRC). It is generally recommended that you should not ever set PYTHONPATH or PYTHONHOME, except as a last resort, exactly because of these kinds of problems.
You can see which Python interpreter you're running by doing:
>>> import sys
>>> sys.executable
And then you can see what directories are ending up in your Python library path (where import statements will look for packages, such as scipy and numpy) by doing one of the following:
>>> import sys
>>> sys.path
or the more readable version:
>>> import sys
>>> for p in sys.path:
... print p
As pointed out by #Mr.F the error was given by the presence of the PYTHONPATH and PYTHONHOME. Deleting them i was able to use the Anaconda version of python.
If you have module not found error, you may need to launch python from anaconda terminal using "python" instead of the shortened "py". I had my module installed properly, but spent forever trying to fix it because of this. Apparently py does not launch the anaconda activated or anaconda base environment, but launches another version of python.
Use
$ conda install package_name instead
Related
I am trying to make a nmap scanner for the InfoSec Certification on freeCodeCamp.org and cannot get Visual Studio Code to recognize that I have installed nmap. I am very beginner and in the process of learning.
from cProfile import run
import nmap
scanner = nmap.PortScanner()
print("Welcome, this is a simple automattion tool")
print("<------------------------------------------->")
When I run this in VS Code I get the following in the terminal:
PS C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1> python3 scanner.py
Traceback (most recent call last):
File "C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1\scanner.py", line 2, in <module>
import nmap
ModuleNotFoundError: No module named 'nmap'
PS C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1>
I have so far:
Updated to the current Python 3.10.7
Installed Nmap the first time from https://nmap.org/ for Windows
Uninstalled Nmap
Reinsalled Nmap using >>>pip3 install python-nmap
For future searchers (as in my comment above), if you installed a module with pip3 but are still getting module import errors, try python3 -m pip install <module-name>.
Not sure how/why this happens (pip3 installing somewhere that python3 is not looking for modules - maybe PYTHONPATH-related), but the above can [usually] help.
It seems that Python cannot find nmap module.
You can either add it to path in Windows via Start -> Edit system environment variables -> Environment variables... and then edit PATH VARIABLE by adding at the end path to nmap module that you have installed or move the module to default Python modules directory which should be C:\Users\YourLogin\AppData\Local\Programs\Python\Python310\Lib\site-packages
The issue
I've pip installed a library called disagree which installed and upgraded without any issues, confirming that the latest version had been successfully installed.
When running import disagree I get the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'disagree'
Identifying what's causing the issue
Section 6.1.2 in https://docs.python.org/3/tutorial/modules.html#packages says that when a module is imported, if it is not in the sys.builtin_module_names, then it proceeds to search for it in the file paths specified in sys.path.
When I run sys.path I get:
['', '/Users/oliverprice/miniconda3/lib/python38.zip',
'/Users/oliverprice/miniconda3/lib/python3.8',
'/Users/oliverprice/miniconda3/lib/python3.8/lib-dynload',
'/Users/oliverprice/.local/lib/python3.8/site-packages',
'/Users/oliverprice/miniconda3/lib/python3.8/site-packages']
Indeed, looking into '/Users/oliverprice/miniconda3/lib/python3.8/site-packages' I can see the module that I've installed. However, it only has the .dist-info file for the package, not the actual package folder. I.e. rather than
name
name-version.dist-info
the only thing present is:
disagree-1.2.6.dist-info
So it looks like there is no actual package in there, and just the .dist-info. Specifically, this is a snapshot of what is in there:
defusedxml
defusedxml-0.6.0.dist-info
dill
dill-0.3.4.dist-info
disagree-1.2.6.dist-info
distutils-precedence.pth
docutils
docutils-0.16.dist-info
easy_install.py
entrypoints-0.3.dist-info
Questions
Is this the reason it is failing to import? If not, what is the reason?
If so, why has this happened?
I have the same issue here. This solution below worked for me.
First of all, check the version of python that you have (must be between python3.8 and 3.10 (included). No python3.7 and python3.11 as I understand.
To check it do this in your notebook/python:
import sys
print(sys.version)
If it matches with the 3.8-3.10 range, then you're ok and skip this step, otherwise you may need to do (in the terminal):
virtualenv venv --python=python3.8
source venv/bin/activate
Let's now install this library from source so that we have the needed source files. Run this in a terminal:
git clone https://github.com/o-P-o/disagree.git
cd disagree
# requirements fixed
pip install numpy pandas mathx scipy tqdm
# install this
pip install .
Now you should be able to import disagree, but with a twist:
from disagree import disagree
# or for example
from disagree.disagree.agreements import BiDisagreements
Please let me know if this works for you.
I will be doing a pull request to fix this library.
Martino
I am trying to use NumPy in Python. I have just installed Anaconda Python 3.7, and that all seemed to go smoothly. However, I cannot import numpy(using the line import numpy). When I do, I get the following error:
C:\Users\jsmith\anaconda3\lib\site-packages\numpy\__init__.py:140: 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\jsmith\anaconda3\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
from . import overrides
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\__init__.py", line 54, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "C:\Users\jsmith\anaconda3\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was:
DLL load failed: The specified module could not be found.
I can see it in the Enviorments tab of Anaconda Navigator, and when I try to use it in Eclipse(Pydev) it shows up under forced builtins. I took a look at my PYTHONPATH, and both my enviorment in Eclipse and my base python directory (jsmith/anaconda3) are in it. I have tried importing other libraries I see under forced builtins,and those work fine, yet numpy seems to be the only one with issues. Calling pip install numpy tells me it is already installed with version 1.18.1. I looked at this stack overflow page, and ran the first command in the answer(conda create -n test numpy python=3.7 --no-default-packages) in anaconda prompt. This worked, and then I realized the test was specific to the question, and tried base instead, and got this error:
CondaValueError: The target prefix is the base prefix. Aborting.
However calling conda activate base did nothing.
As mentioned in the comments by #cel uninstalling and reinstalling numpy using pip uninstall numpy and pip install numpy made it work.
I better way is to
import os
import sys
os.path.dirname(sys.executable)
This will give you the path to your environment. Put the path into the settings for python
Open the Anaconda Prompt:
Then, you have to go to the Conda Environment that you want to use in PowerBI. Am having an environment 'temp', so I activate it first in the 'Anaconda Prompt':
(base) C:\Users\ashish>conda activate temp
Then I go to the directory having the "PowerBI" executable file in the installation folder:
(temp) C:\Users\ashish>cd "C:\Program Files\Microsoft Power BI Desktop\bin"
Then, I launch PowerBI from the Prompt:
(temp) C:\Program Files\Microsoft Power BI Desktop\bin>PBIDesktop.exe
This fixes the NumPy error you are getting. If you want any other package to use with PowerBI, install that package in the respective "Conda Environment" (in my case it is "temp").
Make sure the Python home directory (Anaconda3) has been added to the 'Power BI Desktop' global options in the Python scripting section too.
I'm a newbie to IPython/Anaconda (for Windows 7), and for some reason, I'm getting an import error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-6-484073d472a5> in <module>()
6 import matplotlib.pyplot as plt
7 import requests
----> 8 import pattern
ImportError: No module named pattern
Here's what I did to set up Anaconda/IPython:
Installed Anaconda. I already have a version of python on this computer. The Anaconda distribution was installed to C:\Users\MyName, while the regular python distribution (2.7) was installed to C:\Python27.
When I tried to import some packages (sklearn, pandas, requests, pattern), for some reason those packages just wouldn't import so I installed them manually (downloading them to a local folder on my desktop and running $ python setup.py install, and after that it all seemed to work).
I can run IPython notebooks fine. However, when I try to import pattern specifically, I get that error (which I don't get for sklearn or any of the other packages I installed manually). Printing my sys path from the terminal (import sys print sys.path) and IPython notebook gives:
Terminal:
['C:\\Users\\MyName\\Desktop\\Data Science\\cs109\\Labs', 'C:\\python27\\lib\\site-
packages\\mrjob-0.4.2_dev-py2.7.egg', 'C:\\python27\\lib\\site-
packages\\simplejson-3.3.1-
py2.7.egg', 'C:\\python27\\lib\\site-packages\\pyyaml-3.10-py2.7-win32.egg',
'C:\\python27\\lib\\site-packages\\boto-2.18.0-py2.7.egg',
'C:\\python27\\lib\\site-packages\\requests-2.0.1-py2.7.egg',
'C:\\Windows\\system32\\python27.zip',
'C:\\Python27\\lib\\site-packages\\Orange\\orng', 'C:\\python27\\DLLs',
'C:\\python27\\lib', 'C:\\python27\\lib\\plat-win', 'C:\\python27\\lib\\lib-tk',
'C:\\python27', 'C:\\python27\\lib\\site-packages', 'C:\\python27\\lib\\site-
packages\\PIL', 'C:\\python27\\lib\\site-packages\\win32',
'C:\\python27\\lib\\site-
packages\\win32\\lib', 'C:\\python27\\lib\\site-packages\\Pythonwin']
IPython notebook:
['', 'C:\\Users\\MyName\\Anaconda\\python27.zip', 'C:\\Python27\\lib\\site-
packages\\Orange\\orng', 'C:\\Users\\MyName\\Anaconda\\DLLs',
'C:\\Users\\MyName\\Anaconda\\lib', 'C:\\Users\\MyName\\Anaconda\\lib\\plat-win',
'C:\\Users\\MyName\\Anaconda\\lib\\lib-tk', 'C:\\Users\\MyName\\Anaconda',
'C:\\Users\\MyName\\Anaconda\\lib\\site-packages',
'C:\\Users\\MyName\\Anaconda\\lib\\site-packages\\PIL',
'C:\\Users\\MyName\\Anaconda\\lib\\site-packages\\win32',
'C:\\Users\\MyName\\Anaconda\\lib\\site-packages\\win32\\lib',
'C:\\Users\\MyName\\Anaconda\\lib\\site-packages\\Pythonwin',
'C:\\Users\\MyName\\Anaconda\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-
info', 'C:\\Users\\MyName\\Anaconda\\lib\\site-packages\\IPython\\extensions']
If I do
import pattern
print pattern
It shows that pattern is located at:
C:\python27\lib\site-packages\pattern\__init.pyc
Any thoughts as to why IPython can't import pattern?
I struggled with this - I kept getting an error saying package couldn't be found.
Running below in command prompt worked for me.
conda install -c asmeurer pattern=2.5
On windows, open cmd.exe and type:
conda install pattern
This should do it ;)
Sometimes this happens when you have multiple versions of Python/Anaconda installed on your machine. As the Pattern package does not run on Python 3.4, you need to launch IPython Notebook from the Anaconda server that runs Python 2.7.
So the first step is to make sure that you install the Pattern package using pip in the version of Anaconda that runs Python 2.7.
For example, C:\Users\MyName\Anaconda\Scripts\pip install pattern
The second step is to make sure that you run ipython notebook from the correct path.
For example, C:\Users\MyName\Anaconda\Scripts\ipython notebook
That should do it.
I'm trying to use VirtualEnv for a Flask app that I'm creating since everyone has recommended me to do so. After creating my virtual environment, I installed the libraries that I needed using pip while the environment was activated. I'm running into ImportError problems with this script. The code works fine when I'm not in the virtual environment.
My script:
#!/usr/bin/python
import sc2reader
...
...
When I try to run it I get this:
(flaskapp)xxxx#xxxx-VirtualBox:~/flaskapp/bin$ ./test.py
Traceback (most recent call last):
File "./test.py", line 3, in <module>
import sc2reader
ImportError: No module named sc2reader
I've tried changing the shebang to reflect my VirtualEnv path for Python, but that didn't fix anything. The library is found in my site-packages folder in my virtual environment, so I'm not sure why I'm getting the ImportError.
I've never used VirtualEnv before so I'm assuming I configured it wrong so it's not seeing my site-packages.
Try using
#!/usr/bin/env python
as the shebang.
If that does not work, try seeing what is the output of which python.