python-nmap: nmap.PortScanner() - path error - python

So as I imported python-nmap library to my interpreter:
import nmap
nm = nmap.PortScanner()
nmap.PortScanner() somehow shows me the following error. The installed python-nmap is 0.6.1 version, but the following error shows
File "
...\AppData\Local\Programs\Python\Python37-32\lib\site-packages\nmap\nmap.py",
line 131, in init
os.getenv('PATH')
I'm working with python v3.7 although I installed nmap package + python-nmap.
File "...\networkScanner.py", line 78, in
nmapScanner(subnets, csvfolder) File "...\networkScanner.py", line 21, in nmapScanner
nm = nmap.PortScanner() # instantiate nmap.PortScanner object

For Windows users:
First: closing all terminals and IDLE or any other window you currently have opened when trying to run your script.
Next, open a command line and type
pip uninstall python-nmap
Next, make sure that you installed nmap by typing
nmap
If it is installed, continue to the next step, if not, go to Nmap's official download page
After installation, Open your system's environment variables editor usually found in
My PC > System Information > Advance settings > Environment Variables
select Path for both You and the System
press Edit and enter the full path to your Nmap director
eg ;C:\Program Files (x86)\Nmap\
Press ok and exit the editor.
Now go back to your command line and enter:
pip install python-nmap
Allow it to install and then restart your ide and test your code again.
Reference ('Nmap not found', )

Related

ECCODES ERROR when opening .GRIB file in Spyder

I have accessed Anaconda Prompt for the environment that I will be working.
Once there, I have changed the directory to the place where I have the grib files that I will be working with, in order to install cfgrib, I have used the following command:
conda install -c conda-forge cfgrib
As the Python module depends on ECMWF ecCodes binary library, in the same Anaconda Prompt, I ran the following command:
conda install -c conda-forge eccodes
Then, opened the file in Spyder, and tried to run this simple script:
import xarray as xr
ds = xr.open_dataset('download.grib', engine='cfgrib')
ds
But got the following error:
Can't read index file 'C:\Users\name\Desktop\data\download.grib.90c91.idx'
Traceback (most recent call last):
File "C:\Users\name\anaconda3\envs\Weather\lib\site-packages\cfgrib\messages.py", line 351, in from_indexpath_or_filestream
self = cls.from_indexpath(indexpath)
File "C:\Users\name\anaconda3\envs\Weather\lib\site-packages\cfgrib\messages.py", line 323, in from_indexpath
return pickle.load(file)
EOFError: Ran out of input
Then,
An error ocurred while starting the kernel
ECCODES ERROR : Unable to find boot.def. Context path=D:/bld/eccodes_1593015095851/_h_env/Library/share/eccodes/definitions
Possible causes:
‑ The software is not correctly installed
‑ The environment variable ECCODES_DEFINITION_PATH is defined but incorrect ecCodes assertion failed: `0' in D:\bld\eccodes_1593015095851\work\src\grib_context.c:226
What am I missing here?
Edit 1
The problem also happens if I use Visual Studio Code.
In the terminal, if I am inside the directory that the GRIB files are stored, and I activate the environment that I am working with:
conda activate Weather
And then:
& C:/Users/name/anaconda3/envs/Weather/python.exe c:/Users/name/Desktop/data/3_climate/2mtemp_open.py
It gives the same error as above.
As the error says, ECCODES_DEFINITION_PATH was not set.
As I am using Anaconda on Windows 10, the path is the following
C:/Users/[USER]/Anaconda3/envs/envgeo/Library/share/eccodes/definitions
In order to set the environment variable, one can simply run
setx ECCODES_DEFINITION_PATH "[ECCODES definition path/directory]"
This should solve the problem.
However, a new one may emerge. As the .grib file may take a lot to run, consider using the data in the format NetCDF.

Error with TensorFlow MNIST [duplicate]

Since updating from Homebrew Python 2.7.11 (from 2.7.10) I'm suddenly unable to test register my package on PyPi from the PyCharm IDE console.
Running (as an "External Tool")
python -B setup.py register -r pypitest
I now get
Traceback (most recent call last):
File "setup.py", line 22, in <module>
from setuptools import setup
File "/usr/local/lib/python2.7/site-packages/setuptools/__init__.py", line 12, in <module>
from setuptools.extension import Extension
File "/usr/local/lib/python2.7/site-packages/setuptools/extension.py", line 8, in <module>
from .dist import _get_unpatched
File "/usr/local/lib/python2.7/site-packages/setuptools/dist.py", line 16, in <module>
from setuptools.depends import Require
File "/usr/local/lib/python2.7/site-packages/setuptools/depends.py", line 6, in <module>
from setuptools import compat
File "/usr/local/lib/python2.7/site-packages/setuptools/compat.py", line 17, in <module>
import httplib
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 80, in <module>
import mimetools
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
import io as _io
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Process finished with exit code 1
I'm not sure how to proceed. I only get this issue if I execute from within my IDE's console. If I do it directly at the system command line (Terminal on OS X) I have no problems.
OS X 10.11.3; Homebrew Python 2.7.11; PyCharm 5.0.3
tl;dr: Fix this issue by doing one of the following:
type hash -r python, OR
log out and log in.
EDIT: An answer to my related question makes it clear what's happening here. When you install a new version of python, you may need to run hash -r python to tell bash to reset the "cached" location to the python executable.
In my case, I was typing python, which was on my $PATH at /usr/local/bin/python. But bash was still using the old cache location /usr/bin/python. So, the old executable was called, but the new path was provided to python in sys.argv[0]. This means that the old executable was running, but the new sys.executable value caused all the wrong modules to get loaded (including the io module).
I'm having the same problem. I installed python 2.7.11 via an installer from Python.org. Strangely, the issue seems to be related to some subtle difference between how OSX launches python when I invoke it from the shell using the full path vs. using just the word python.
So, for me, this works (invoking python via the full path /usr/local/bin/python):
$ which python
/usr/local/bin/python
$ /usr/local/bin/python -c "import io"
$
... but this doesn't:
$ python -c "import io"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
So, as a workaround, you can try doing the same thing.
Elsewhere, I've posted a separate question about this puzzling behavior. Maybe somehow merely calling python invokes some strange mix of the 2.7.11 executable with the 2.7.10 dylibs??
According to https://github.com/klen/python-mode/issues/634:
I had the same issue, but successfully fixed. In my case I compiled
python and vim with homebrew, when PYTHON_PATH has been specified and
set to one of my dev environments, where I also had some libraries,
including io. Workaround was simple: open new terminal, make sure that
you do not have custom PYTHON_PATH, uninstall python, uninstall vim.
Reinstall both of them.
and
Problem solved.
Culprit is the update from python 2.7.10 to 2.7.11.
If you are using conda package control, simply run "conda install
python=2.7.10" will solve this problem.
This doesn't give the root cause though. Since this happens with _io, this looks like a bug in python 2.7.11 (unlikely, there would be a world-scale outcry and a prompt fix if it was) or some packaging bug or version mismatch specifically with the homebrew version (and maybe some related ones, too).
Try to import _io in the console and if it succeeds, check if it was loaded from the same path.
Reinstall python.
brew unlink python && brew reinstall python
Secure the path
export PYTHONPATH=$PYTHONPATH:/usr/local/bin/
BACKUP and Change the order of "paths" file.
sudo nano /etc/paths
it seems, the order of paths, it is decisive to run python properly. In my case, the result was:
#sudo nano /etc/paths
/usr/bin
/usr/local/bin
/bin
/usr/sbin
/sbin
On my mac, path is like this.
$ which python
/usr/local/bin/python
Now I can run both:
$ /usr/local/bin/python -c "import io"
$ python -c "import io"
I had the same issue, it is successfully fixed by just replacing the _io.so file.
sudo find / -name _io.so
copy the path of the _io.so file which DOES NOT belong to python-2.7.11. For example, copy the path of _io.so which is under python-2.7.5:
/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Replace the /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so file with the _io.so that you just found.
This happened to me as well in MacVim. I solved it by making sure :python print(sys.path) is using system Python (e.g. /Library/Python/2.7/...)
Since I installed MacVim via Homebrew, I just did that by:
Spawn a new shell that had which python -> /usr/bin/python. For my case I needed to remove the pyenv line from my .bash_profile. If you installed Python via Homebrew you may want to brew unlink python first
brew reinstall macvim
If your problem is caused by anaconda, it is unnecessary to remove //anaconda directory.
Just open your ~/.bash_profile, find the line
export PATH="//anaconda/bin:$PATH
and comment it out, then restart your terminal session.
Another quick workaround if you don't mind sticking with Python 2.7.10 is to specify the path of the Python interpreter executable that will be used for the virtualenv. On OSX that path is usually /usr/bin/python:
virtualenv venv --python=/usr/bin/python
Can't add comment (?) so this just to share my exp., downgrade to 2.7.10 works fr me.
I got this error after a failed NLTK download, I needed to uninstall anaconda:
sudo rm -rf ~/anaconda
update PATH variable
This happened when I already had tried to create a venv in a folder, and mistakenly was trying to initialize a second one! So I just removed venv directory and re-ran the command. Very likely this is not the answer to this solution, but searching my error brought me here, so it may help some others who are stuck.
I solved this issue by removing the symbolic link that was in /usr/local/bin and copying the actual python binary, that was pointed to by said link, there.
I had the same issue when I tried to use PyCharm. Solved by setting "python interpreter" in project configuration to point to the python virtual env I wanted to use, which was an Anaconda env. Somehow the interpreter path was missing the "anaconda" portion of ~/.../anaconda/.../_io.so. No need to uninstall anaconda.

'lessc' is not recognized as an internal or external command, operable program or batch file

I have been using Sublime Text 3 to compile .less css at work, but I can't get it to work on my local machine. I think it has something to do with the path variable for lessc, but I can't figure out how to find the path variable that I need to add to my path variable to make it work. Can some one help?
I'm using Windows 7 with Sublime Text 3.
Here is the error:
Writing file /C/xampp/htdocs/project/sites/project.localhost/themes/project/less/home.less with encoding UTF-8 (atomic)
[less2css] Converting C:\xampp\htdocs\project\sites\project.localhost\themes\project\less\home.less to C:\xampp\htdocs\project\sites\project.localhost\themes\project\css\home.css
error: less2css error: [WinError 2] The system cannot find the file specified
Traceback (most recent call last):
File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 549, in run_
return self.run(edit)
File "less2css in C:\Users\myMachine\AppData\Roaming\Sublime Text 3\Installed Packages\Less2Css.sublime-package", line 48, in run
File "less2css in C:\Users\myMachine\AppData\Roaming\Sublime Text 3\Installed Packages\Less2Css.sublime-package", line 15, in __init__
File "less2css in C:\Users\myMachine\AppData\Roaming\Sublime Text 3\Installed Packages\Less2Css.sublime-package", line 29, in show
File "C:\Program Files\Sublime Text 3\sublime.py", line 86, in error_message
sublime_api.error_message(msg)
TypeError: String required
Running l e s s c " . / m a i n . l e s s " " . . / c s s / m a i n . c s s " - - s o u r c e - m a p - - n o - c o l o r
This is a good question, because the lessc path is dissimilar in many ways to normal installation paths on Windows. I was able to confirm that lessc does need to be added to your Windows environment variable called PATH in order to for sublime-less2css to work properly, and this is directly from the maintainer of the sublime-less2css module: https://github.com/timdouglas/sublime-less2css
Open Control Panel
type 'env' in the Control Panel Search Bar to bring up the 'Edit the system environment variables' option (select this option, then tell the User Account Control dialog to 'Continue')
click the 'Environment Variables' button
Go to the System Variables section --> click once on the line that says PATH --> click 'Edit'
Add the following to the end of the strings in the window that comes up:
;C:\Users\{add_your_Windows_username_here}\AppData\Roaming\npm
Since my Windows user name is cknoettg, mine looks like this:
;C:\Users\cknoettg\AppData\Roaming\npm
Finally, click OK --> OK --> OK
Now, retry the program.
Important proviso: For this solution to work, you must have installed less on your Windows machine using npm - the Node.js Package Manager. (Which you can get here: http://nodejs.org/)
If you used a different method to install lessc, the exact path to add to your environment variables is going to be different than what I have suggested. Let's say you installed 'lessc' directly in a folder called "C:\less\bin". In that instance, you would add:
;C:\less\bin
to your environment variable PATH.
Also: I noticed in the error message that you posted the following line:
less2css in C:\Users\myMachine\AppData\Roaming\Sublime Text 3\Installed Packages\Less2Css.sublime-package
It is possible that your Python file is hardcoded with the path C:\Users\myMachine\AppData\Roaming\Sublime Text 3\Installed Packages\Less2Css.sublime-package. IF that is the case, it is possible that your lessc program is in the path: C:\Users{insert_your_Windows_username_here}\AppData\Roaming\Sublime Text 3\Installed Packages\ .
IF this is true, then you will not only have to modify your Windows environment variable PATH with:
;C:\Users\{insert_your_Windows_username_here}\AppData\Roaming\Sublime Text 3\Installed Packages\
You will also have to manually edit your Python file by substituting the text 'myMachine' with your current Windows username on the machine that you are located on currently. You could even try just making this direct edit to the Python code without changing the Windows environment variable, but it may or may not work.
To see a way to run your program WITHOUT editing the environment variable, you can see here (although I don't recommend it for a variety of reasons, not the least of which is the additional typing involved each time you run your script): How to install and run lessc on top of node.js and Windows?
Good luck!
Because your system cannot find the "lessc" commandline tool, you can simply install it using npm if you having node in your system:
npm install -g less
You can install less compiler by
npm install less
then you can find the compiler in this path
\node_modules\less
then copy the lessc file to where your .less file is, then run the compiler in cmd
lessc styles.less styles.css
done!
On windows you can install git-bash terminal.
Then execute npm install less. This would install it locally.
Then in the git-bash terminal navigate to your project folder and execute
./node_modules/less/bin/lessc css/styles.less css/styles.css
This Command Solved my issue:
npm install -g less

pycallgraph with pycharm does not work

I'm using mac os x and trying to setup pycallgraph.
Ive installed pycallgraph with pip and graphviz with homebrew.
Everything works from shell.
But not from pycharm.
from pycallgraph import PyCallGraph
from pycallgraph import Config
from pycallgraph import GlobbingFilter
from pycallgraph.output import GraphvizOutput
config = Config()
config.trace_filter = GlobbingFilter(exclude=[
'pycallgraph.*',
])
graphviz = GraphvizOutput(output_file='filter_exclude.png')
with PyCallGraph(output=graphviz, config=config):
def my_fun():
print "HELLO"
my_fun()
/Users/user/Projects/py27/bin/python /Users/user/Projects/py27_django/test2.py
Traceback (most recent call last):
File "/Users/user/Projects/py27_django/test2.py", line 15, in <module>
with PyCallGraph(output=graphviz, config=config):
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 32, in __init__
self.reset()
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 53, in reset
self.prepare_output(output)
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 97, in prepare_output
output.sanity_check()
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/output/graphviz.py", line 63, in sanity_check
self.ensure_binary(self.tool)
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/output/output.py", line 96, in ensure_binary
'The command "{}" is required to be in your path.'.format(cmd))
pycallgraph.exceptions.PyCallGraphException: The command "dot" is required to be in your path.
Process finished with exit code 1
Here:
/Users/user/Projects/py27/ -> virtualenv dir
/Users/user/Projects/py27_django/ -> project dir
What does it want from me?
Install graphviz in MacOS by using:
brew install graphviz
or in Ubuntu by using:
sudo apt-get install graphviz
Then you can test dot by using:
dot -v
You can also download pkg from here
The answer is:
In menubar:
Pycharm -> Run -> Edit Configurations...
In dialog:
for selected .py file or for Defaults/Python:
Environment field group:
Environment variables > ... -> + ->
Add entry:
Name: PATH
Value: /usr/local/bin
Include print environment variables should be selected
FWIW, this is a behaviour which two other users have filed as an Issue in PyCharm's bugtracker: https://youtrack.jetbrains.com/issue/PY-17816
I'll update this post if the developers comment there.
[Update] On September 22nd 2016, Pycharm developers offered a fix in the Early Access version. https://blog.jetbrains.com/pycharm/2016/09/pycharm-2016-3-eap-is-available-with-initial-support-for-python-3-6/, but this does not seem to have fixed the problem yet.
This process worked for my environment; I got the same "dot" error after I compiled. Unfortunately, I was looking for a visual representation of the code which shows inheritance, function calls, more like a flow chart. On the UP-and-UP, I Understand what a profiler does this one worked great!
Pycharm: 2020.3.3
Python 3.8
PyCallGraph3
Venv Environment in Pycharm
For it to work in PyCharm on Windows 10:
Install the package under your interpreter: pycallgraph3
File > Settings > Project > Python Interpreter
Install the program called GraphViz (https://graphviz.org/)
Under your Run/Debug Configurations go to Environment Variables:
Paste the following line at the end of the massive list
;C:\Program Files\Graphviz\bin;
After here, I didn't test its validity but did it anyway if it didn't work try adding it to your windows path.
In Windows under:
System Properties > Environment Variables
FOR USER WINDOW (TOP)
Edit > PATH > NEW> add Entry: C:\Program Files\Graphviz\bin\
FOR SYSTEM VARIABLES WINDOW (BOTTOM):
Edit > PATH > NEW > add a New Entry: C:\Program Files\Graphviz\bin\

Importing modules with python

I'm working with python 2.7 (32-bit) on Windows Vista. I downloaded some libraries including numpy, scipy, and pygame. When I try to import these modules the output says
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import numpy
ImportError: No module named numpy
I can find these modules in my python folders but for some reason it doesn't want to recognize it or some thing. (I made sure the file were compatible before downloading.)
Each package should contain a setup.py file. Run this with the command python setup.py install
For more information:
http://www.scipy.org/Installing_SciPy/Windows
http://pygame.org/install.html
"Everytime I run the command "python setup.py install" in the python shell it says SyntaxError: invalid syntax "
Please create a folder where you unzip the "numpy.zip" file, say the folder name is "c:\numpy"
Open a MS-DOS terminal (as described here : http://en.wikipedia.org/wiki/Command-line_interface), and type :
cd c:\numpy
python setup.py config
python setup.py install
This will set up the needed files in the correct folders for your python.
Enjoy !
To properly install this module:
In the Windows search bar (START MENU) type Command Prompt
Right-click on the Command Prompt icon (DO NOT go to cmd)
Click Run as Administrator
in the COMMAND PROMPT (DO NOT open cmd) type:
pip install numpy
This will install that module.
NOTE: If you are NOT in admin mode, you will get a message saying a fatal error has been raised.

Categories

Resources