How to fix "No module named 'nmap'" - python

import nmap
ModuleNotFoundError: No module named 'nmap'
the above is the result when trying to run the code after importing nmap. (I have installed python-nmap using pip in cmd)

i found out the issue. when i chose a python env eg- python 3.8 32bit from the IDE, i chose a custom version thats why the imports dont work. when i chose the default env it worked. anyways thank for the help. there is nothing wrong with the IDE

I had to do two things to get it working:
Install the latest version of Python3 (3.9.6) https://www.python.org/downloads/release/python-396/
On your terminal:
pip3 install python-nmap

I had to do the following to get things to work:
On your terminal, switch to root privilege:
su - root
Then, install python-nmap module:
pip3 install python-nmap
Reference: https://github.com/securipy/nmap-scan/issues/26

STEP 1:
Uninstall the package using:
pip3 uninstall python-nmap
STEP 2:
Install the package:
pip3 install --user python-nmap

Related

ModuleNotFoundError: No module named 'cv2' (only in vscode with venv)

When I try to install opencv-python I get the following error:
ModuleNotFoundError: No module named 'cv2'
I tried to install cv2 via these commands:
pip install opencv-python
pip install opencv-contrib-python
pip install opencv-python opencv-python-headless
python3 -m pip install opencv-python
pip3 install opencv-python --upgrade
However, the problem remains.
I have noticed that this problem occurs only in the virtual environment (venv) of VScode.
In fact, if I launch this code from the terminal it does not give me any error and it returns me the version of cv2
import cv2
print (cv2.__version__)
Reply -> 4.6.0
I use Python 3.9
EDIT:
This is a screenshot of the problem
The problem do not appear if I create a new venv
Use Ctrl+Shift+P to open the command palette search and select Python:Select Interpreter, then select the correct interpreter, this will solve your problem.
Tip: Every time you choose a new interpreter, please create a new terminal to activate the environment.
As far as your question is concerned, you can follow these steps:
Select the interpreter in the virtual environment according to the above method
Create a new terminal
Use pip install opencv-python to install the package
Also you can use pip show opencv-python to see where the package is installed.
What solved it for me was adding the following to the .vscode/settings.json config file
// Add venv to python path
"python.analysis.extraPaths": [
"${workspaceFolder}/venv/lib/python3.8/site-packages"
]
change venv to the name of your virtual env folder.

Python - Notion API - Can't import module

I'm trying to use Notion API for some automation processes but I am having some trouble importing the packages and I already try a lot of imports. I've this code:
from notion_database.database import Database
my_token = "my_token"
D = Database(integrations_token=my_token )
print(D.list_databases(page_size=100))
To run this code I made the following imports:
pip install notion-database
pip install notion-py
pip install "notion==0.0.25"
pip install notion
All of them were installed correctly and I don't have my script name as "notion.py" :D
But when I run my code I got:
from notion_database.database import Database
ModuleNotFoundError: No module named 'notion_database'
Does anyone know what I am doing wrong?
Thanks for the help!
It looks your code is fine.
More likely, your python and pip points onto two different python versions.
I would suggest you create an environment (virtualenv or pyenv) and reinstall the packages using this command:
sudo python -m pip install notion-database
sudo python -m pip install notion-py
sudo python -m pip install "notion==0.0.25"
sudo python -m pip install notion
maybe you have not install notion successfully.
try to replace pip install notion
to pip install notion --user
,after that maybe there is no error with run "import notion".
good luck!

How to install python packages from CMD?

I want to install urllib2 and JSON but it doesn't seem to let me. I tried using pip install in cmd which didn't work and also tried specifying the Scripts path and then doing the command but that does not work either. I am on 64-bit and I have used some command in pip like pip install python3 (package name) which worked for me but I haven't install anything in some time so I don't remember what the command was exactly that worked for me.
Both of those should be apart of the standard library so there shouldn't be a need to reinstall using pip. Try reinstalling python3 (uninstall then reinstall) and check the "add to path" button at the bottom of the installer before installation.
You can also try pip3 install (package name) and also try to update it to the latest version using simocat's answer
Edit: I believe you don't need to install these packages they come as part of python 3.x
Have you tried using the command pip install (package name)?
You can also try to upgrade pip to the latest version with pip install --upgrade pip and then install a package.
EDIT:
Please note that The urllib2 module has been split across several modules in Python 3 named urllib.request and urllib.error. There is no need to install urllib2. Just import urllib.request into your script
What does:
python -m ensurepip --upgrade
in cmd respond?
(It is always helpful to post the Error output you receive from your commandline) and on these kinds of topics in general you may check: https://stackexchange.com/
Btw. Here is a related q&a:
Installing pip on windows?

Unable to install LIbraries for Python3.6.5

I had pyhton2.7 and Python3.5 in my laptop but to use f string, I installed pyhton3.6.5 and removed python3.5. Now I have python2.7 and Python3.6.5. But I am not able to install any libraries for the python3.6.5
I have tried this but it doesn't works
Please let me know how can I install modules for the python3.6.5
Try this
sudo python3.6 -m pip install [Package_to_install]
I hope it will work.
Check the installation in your system, if there are several python3 installs in your system it might be an issue.
Either uninstall the other version of python3 or create a virtual environment and then install the library.
Check the description at https://www.alexkras.com/how-to-use-virtualenv-in-python-to-install-packages-locally/

No module named 'pymysql'

I'm trying to use PyMySQL on Ubuntu.
I've installed pymysql using both pip and pip3 but every time I use import pymysql, it returns ImportError: No module named 'pymysql'
I'm using Ubuntu 15.10 64-bit and Python 3.5.
The same .py works on Windows with Python 3.5, but not on Ubuntu.
Sort of already answered this in the comments, but just so this question has an answer, the problem was resolved through running:
sudo apt-get install python3-pymysql
Use:
import pymysql
Not:
import PyMySQL
That works for me.
After trying a few things, and coming across PyMySQL Github, this worked:
sudo pip install PyMySQL
And to import use:
import pymysql
If even sudo apt-get install python3-pymysql does not work for you try this:
Go to the PyMySQL page and download the zip file.
Then, via the terminal, cd to your Downloads folder and extract
the folder
cd into the newly extracted folder
Install the setup.py file with: sudo python3 setup.py install
Make sure that you're working with the version of Python that think you are. Within Python run import sys and print(sys.version).
Select the correct package manager to install pymysql with:
For Python 2.x sudo pip install pymysql.
For Python 3.x sudo pip3 install pymysql.
For either running on Anaconda: sudo conda install pymysql.
If that didn't work try APT: sudo apt-get install pymysql.
If all else fails, install the package directly:
Go to the PyMySQL page and download the zip file.
Then, via the terminal, cd to your Downloads folder and extract the folder.
cd into the newly extracted folder.
Install the setup.py file with: sudo python3 setup.py install.
This answer is a compilation of suggestions. Apart from the other ones proposed here, thanks to the comment by #cmaher on this related thread.
To get around the problem, find out where pymysql is installed.
If for example it is installed in /usr/lib/python3.7/site-packages, add the following code above the import pymysql command:
import sys
sys.path.insert(0,"/usr/lib/python3.7/site-packages")
import pymysql
This ensures that your Python program can find where pymysql is installed.
fwiw, for a conda env:
conda install -c anaconda pymysql
For windows or one using google colab, you can try this
!pip install pymysql
import pymysql
sudo apt-get install python3-pymysql
This command also works for me to install the package required for Flask app to tun on ubuntu 16x with WISG module on APACHE2 server.
BY default on WSGI uses python 3 installation of UBUNTU.
Anaconda custom installation won't work.
I had this same problem just now, and found the reason was my editor (Visual Studio Code) was running against the wrong instance of python; I had it set to run again python bundled with tensorflow, I changed it to my Anaconda python and it worked.
Just a note:
for Anaconda install packages command:
python setup.py install
if you are using SPYDER IDE , just try to restart the console or restart the IDE, it works
I also got this error recently when using Anaconda on a Mac machine.
Here is what I found:
After running python3 -m pip install PyMySql, pymysql module is under /Library/Python/3.7/site-packages
Anaconda wants this module to be under /opt/anaconda3/lib/python3.8/site-packages
Therefore, after copying pymysql module to the designated path, it runs correctly.
Another common issue causing the error message to appear is related to conda environments in jupyter notebook and jupyter lab.
After successfully installing a module (pymysql in this case) in one environment, import may seem to fail because the environment has not been correctly registered. To solve this it is necessary to manually add kernels for each environment.
Solution and more details can be found here.
I tried installing pymysql on command prompt by typing
pip install pymysql
But it still dont work on my case, so I decided to try using the terminal IDE and it works.
I ran into the same problem earlier, but solved it in a way slightly different from what we have here. So, I thought I'd add my way as well. Hopefully, it will help someone!
sudo apt-get install mysql-client didn't work for me. However, I have Homebrew already installed. So, instead, I tried:
brew install mysql-client
Now, I don't get the error any more.
You can also visit this lien pip install PyMySQL
You just need to install:
python3 -m pip install PyMySQL
The following pymysql version worked for me:
pip install pymysql==1.0.2
For anaconda user,
I got this error message.
ModuleNotFoundError: No module named 'pymysql'
So tried 'pip install pymysql' but got below.
Requirement already satisfied: pymysql
What worked for me is,
python file.py (NOT py file.py)

Categories

Resources