ndiff - PYTHONPATH environment variable - python

I have a problem with Ndiff, I can't execute it. (Nmap works perfect)
So I try to use ndiff and get this error message:
Could not import the ndiff module: 'No module named ndiff'.
I checked in these directories:
/usr/local/bin
/usr/local/bin
/usr/local/bin/ndiff
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
/Library/Python/2.7/site-packages
If you installed Ndiff in another directory, you may have to add the
modules directory to the PYTHONPATH environment variable.
So I search for the path of ndiff and export it to PYTHONPATH. But it doesn't work out, what I am doing wrong?
which ndiff
/usr/local/bin/ndiff
I re-install ndiff and nmap with homebrew and know I get this message, after I try to execute this code
$ ndiff firstScan.xml secondScann.xml > diffScan
Traceback (most recent call last):
File "/usr/local/bin/ndiff", line 84, in <module>
sys.excepthook = ndiff.excepthook
AttributeError: 'module' object has no attribute 'excepthook'

The command you're trying to run /usr/local/bin/ndiff, is a Python script in disguise (that is, it doesn't have the .py extension).
Somewhere at the top of that script, it tries to import the ndiff module itself:
import ndiff
which, seen the path /usr/local/, is probably installed in /usr/local/lib/python2.7/site-packages/(*). You need to add this path to your PYTHONPATH:
export PYTHONPATH=${PYTHONPATH}:/usr/local/lib/python2.7/site-packages
Now, the script can pick up the module, and happily continue.
(*) it may get installed somewhere else, in which case you'll have to locate it manually. You could try something like find /usr/local -name ndiff.py to see where it is installed.
The second error, after your re-install, could be caused by a loose ndiff.py somewhere in your current working directory. In that case, /usr/local/bin/ndiff will try to import that file, and think it's the actual ndiff module. Since it's not, it will fail when it tries to access some of the modules attributes like ndiff.excepthook, which that loose ndiff.py doesn't have. Remove the loose file and you should be good to go.

It's probably not necessary to change the PYTHONPTH environment variable, what happens is that the ndiff script is pointing either to a wrong path or to a wrong/non-existent file.
Just edit the ndiff script (passed as a binary) located likely in /usr/bin/ndiff:
# sudo vi /usr/bin/ndiff
and locate the line: INSTALL_LIB = '...
It should read the full path to your python site-packages directory, for example:
INSTALL_LIB = '/usr/lib/python2.7/site-packages'
Seek for a file named ndiff.py in there:
# sudo find /usr/lib/python2.7/site-packages -name ndiff.py
If there is none present, you must create it and paste all the content present here in it: https://raw.githubusercontent.com/nmap/nmap/master/ndiff/ndiff.py
It should all work then.

Related

ModuleNotFoundError: No module named 'asyncio.streams'

i am working on a long project in Django and suddenly i faced this error:
import asyncio
File "C:\Users\AppData\Local\Programs\Python\Python38\lib\asyncio\__init__.py", line 17, in <module>
from .streams import *
ModuleNotFoundError: No module named 'asyncio.streams'
I tried to instal it using : pip install asyncio, But again it gave some errors :
Traceback (most recent call last):
File "c:\users\appdata\local\programs\python\python38\lib\shutil.py", line 587, in _rmtree_unsafe
with os.scandir(path) as scandir_it:
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\AppData\\Local\\Temp\\pip-req-tracker-ua43f6rj'
please Tell me how can i fix it . I am Using Python 3.8.1
Please reinstall python3.8.1 for windows 10
Packages and modules in python can be imported when they appear in the PYTHONPATH environement variable or in the sys.path list.
On each PYTHONPATH expanding, will ends up in the sys.path list.
so make sure that, the instalation of your asyncio was successeful and its path exist in the sys.path list. how you check? see below:
in comand line or in script.py type:
import sys
p_asyn=r'C:\Users\AppData\Local\Programs\Python\Python38\lib\asyncio'
if p_asyn not in sys.path:
print('asyncio not in the sys path list! :-(')
sys.path.append(p_asyn)
its better to append new paths to the PYTHONPATH rather than editing the sys.path.
Anywa, if the module you are trying to import (asuncio) is a built in lib/module you should check if the pyhton installation was successful and the path environement variable edited correctly and has all paths that should be.
in windows make sure that python installation dir appears in the path. if not use the set command,
set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib
Python usually stores its library (and thereby your site-packages folder) in the installation directory. So, if you had installed Python to C:\Python\, the default library would reside in C:\Python\Lib\ and third-party modules should be stored in C:\Python\Lib\site-packages.
This attended to windows users.
for further reading, enter the link here
using_py2
using_py3

pdfminer - ImportError: No module named pdfminer.pdfdocument

I am trying to install pdfMiner to work with CollectiveAccess. My host (pair.com) has given me the following information to help in this quest:
When compiling, it will likely be necessary to instruct the
installation to use your account space above, and not try to install
into the operating system directories. Typically, using "--
home=/usr/home/username/pdfminer" at the end of the install command
should allow for that.
I followed this instruction when trying to install.
The result was:
running install
running build
running build_py
running build_scripts
running install_lib
running install_scripts
changing mode of /usr/home/username/pdfminer/bin/latin2ascii.py to 755
changing mode of /usr/home/username/pdfminer/bin/pdf2txt.py to 755
changing mode of /usr/home/username/pdfminer/bin/dumppdf.py to 755
running install_egg_info
Removing /usr/home/username/pdfminer/lib/python/pdfminer-20140328.egg-info
Writing /usr/home/username/pdfminer/lib/python/pdfminer-20140328.egg-info
I don't see anything wrong with that (I'm very new to python), but when I try to run the sample command $ pdf2txt.py samples/simple1.pdf I get this error:
Traceback (most recent call last): File "pdf2txt.py", line 3, in <module>
from pdfminer.pdfdocument import PDFDocument ImportError: No module named pdfminer.pdfdocument
I'm running python 2.7.3. I can't install from root (shared hosting). The most recent version of pdfminer, which is 2014/03/28.
I've seen some posts on similar issues ("no module named. . . " but nothing exactly the same. The proposed solutions either don't help (such as installing with sudo - not an option; specifying the path for python (which doesn't seem to be the issue), etc.).
Or is this a question for my host? (i.e., something amiss or different about their setup)
I had an error like this:
No module named 'pdfminer.pdfinterp'; 'pdfminer' is not a package
My problem was that I had named my script pdfminer.py which for the reasons that I don't know, Python took it for the original pdfminer package files and tried to compiled it.
I renamed my script to something else, deleted all the *.pyc file and __pycache__ directory and my problem was solved.
use this command worked for me and removed the error
pip install pdfminer.six
Since the package pdfminer is installed to a non-standard/non-default location, Python won't be be able to find it. In order to use it, you will need to add it to your 'pythonpath'. Three ways:
At run time, put this in your script pdf2txt.py:
import sys
# if there are no conflicting packages in the default Python Libs =>
sys.path.append("/usr/home/username/pdfminer")
or
import sys
# to always use your package lib before the system's =>
sys.path.insert(1, "/usr/home/username/pdfminer")
Note: The install path specified with --home is used as the Lib for all packages which you might want to install, not just this one. You should delete that folder and re-install with --
home=/usr/home/username/myPyLibs (or any generic name) so that when you install other packages with that install path, you would only need the one path to add to your local Lib to be able to import them:
import sys
sys.path.insert(1, "/usr/home/username/myPyLibs")
Add it to PYTHONPATH before executing your script:
export PYTHONPATH="${PYTHONPATH}:/usr/home/username/myPyLibs"
And then put that in your ~/.bashrc file (/usr/home/username/.bashrc) or .profile as applicable. This may not work for programs which are not executed from the console.
Create a VirtualEnv and install the packages you need to that.
I have a virtual environment and I had to activate it before I did a pip3 install to have the venv see it.
source ~/venv/bin/activate

Updating PYTHONPATH variable pointing to a dropbox directory containing a space

I'm trying to import a module for python that I have written that is contained in a Dropbox folder whose path contains a space. Following the comments here, I don't want to do a sys.path.append(path_to_repository) every time I use python, I'd rather just update my bash profile to point to the correct Dropbox folder once.
I've tried adapting the code from the previous page by appending the following lines to my ~/.bash_profile:
PYTHONPATH ="/Users/myusername/Dropbox (projectname)/REPOSITORY_NAME"
export ${PYTHONPATH}
When I close the terminal window and reopen, I get the following error message:
-bash: PYTHONPATH: command not found
-bash: export: `/Users/myusername/Dropbox': not a valid identifier
-bash: export: `(projectname)/REPOSITORY_NAME': not a valid identifier
and (not suprisingly) when I then try to import from the repository in python, I get a module not found:
>>> from REPOSITORY_NAME import myfile
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named REPOSITORY_NAME
Does anyone have any solutions?
Some questions/possibilities I'm thinking of -
1) Does it have anything to do with my Anaconda configuration? (Anaconda runs in a virtual env)
2) Does it has anything to do with the folder with python code being installed in Dropbox?
3) Could it be that spaces in pythonpath are not interpreted correctly?
4) Is there any problem with this being the same directory that syncs to github and bitbucket?
Thanks in advance for your help.
*Edit:
The solution seems to be to 1) erase the extra space in the first line and 2) repalce the ${PYTHONPATH} with PYTHONPATH in the second line, i.e. to adjust ~/.bash_profile to have the following line:
PYTHONPATH="/Users/myusername/Dropbox (projectname)/REPOSITORY_NAME"
export PYTHONPATH
I had a similar problem a while ago. The error message is indicating that the problem lies in the space in the directory path - the bash_profile is being truncated by the space and it is splitting the path into 2. It may be a problem with the way bash handles spaces, but I am not 100% sure.
Here is one solution that worked for me:
export PYTHONPATH="/Users/myusername/Dropbox (projectname)/REPOSITORY_NAME"
It is similar to what you have, but export and PYTHONPATH are in the same line. I don't think this would interfere with Dropbox, Github, Bitbucket, Anaconda (or any other virtualenv like Enthought) etc., as long as you as have a _init__.py' file in each directory where you have your .py files.
Hope this helps
Yeah, you put a space before the = sign when exporting PYTHONPATH:
PYTHONPATH ="/Users/myusername/Dropbox (projectname)/REPOSITORY_NAME"
Should be:
PYTHONPATH="/Users/myusername/Dropbox (projectname)/REPOSITORY_NAME"

changing virtualenv folder on windows

after a computer fix my python projects dir (windows) changed (say from d: to f:).
now all my virtualenvs are broken. after activating the env the project inside the virtualenv can't find the dependencies and the custom scripts (from the env\scripts folder)won't work
tried running:
virtualenv --relocateble ENV_NAME (with the env name ..)
like in this stackoverflow question and it outputted a lot of lines like:
Script agent\Scripts\deactivate.bat cannot be made relative
and my virtualenv is still broken.
when I manually changed activate.bat set VIRTUAL_ENV to the new path. some scripts work again. but the relocate scripts still doesn't run and most of the scripts are still broken
even running the python interpeter fails with:
Traceback (most recent call last):
File "F:\Python27\learn\agent\agent\lib\site.py", line 677, in <module>
main()
File "F:\Python27\learn\agent\agent\lib\site.py", line 666, in main
aliasmbcs()
File "F:\Python27\learn\agent\agent\lib\site.py", line 506, in aliasmbcs
import locale, codecs
File "F:\Python27\learn\agent\agent\lib\locale.py", line 19, in <module>
import functools
ImportError: No module named functools
is there any way to fix this? HELP
Update: I also changed manually the shebang python interpeter line in all scripts in ENV\Scripts. now all fail with the same python failure as above
Another Update: to #udi the system python path is:
['', 'C:\\dev\\Python27\\lib\\site-packages\\distribute-0.6.37-py2.7.egg', 'C:\\
dev\\Python27\\lib\\site-packages\\pip-1.3.1-py2.7.egg', 'C:\\dev\\Python27\\lib
\\site-packages\\numpy-1.7.1-py2.7-win32.egg', 'C:\\dev\\Python27\\lib\\site-pac
kages\\pandas-0.11.0-py2.7-win32.egg', 'C:\\dev\\Python27\\lib\\site-packages\\p
ytz-2013b-py2.7.egg', 'C:\\dev\\Python27\\lib\\site-packages\\python_dateutil-2.
1-py2.7.egg', 'C:\\dev\\Python27\\lib\\site-packages\\six-1.3.0-py2.7.egg', 'C:\
\dev\\Python27\\lib\\site-packages\\tornado-3.0.1-py2.7.egg', 'C:\\dev\\Python27
\\lib\\site-packages\\pyzmq-13.1.0-py2.7-win32.egg', 'C:\\dev\\Python27\\lib\\si
te-packages\\pygments-1.6-py2.7.egg', 'C:\\Windows\\system32\\python27.zip', 'C:
\\dev\\Python27\\DLLs', 'C:\\dev\\Python27\\lib', 'C:\\dev\\Python27\\lib\\plat-
win', 'C:\\dev\\Python27\\lib\\lib-tk', 'C:\\dev\\Python27', 'C:\\dev\\Python27\
\lib\\site-packages', 'C:\\dev\\Python27\\lib\\site-packages\\setuptools-0.6c11-
py2.7.egg-info']
since I can't run python from the virtualenv, I can't print the python path from there
Correcting python directory path in ENV_FOLDER\Lib\orig-prefix.txt helped me
Seems like your system and local environments create a mix of libraries and binaries from different versions of python.
Chances are you would need to delete Lib, Scripts and Include and start again with virtualenv .. You might be able to save the site-packages folder, but if you have requirements.txt files, you should probably reinstall packages instead (see also: How do I install from a local cache with pip? ).
Anyway, I believe you can create a script that does all this in one step.
I installed both py2 and py3 on my windows 10. And got this error by create virtualenv by using virtualenv xxx directly. After purging folder xxx and reinstalling with virtualenv -p TARGET_PY_EXE xxx everything works smoothly.
Hope this will help multiple python windows users.
By the way, I simply create env variables as PY2 and PY3 instead of adding absolute paths into PATH.

virtualenv and python path

i did a virtualenv in c:\users\devtool.virtualenv\devenv
After i run activate.bat.
And last i wrote a simple py file to test environment:
import os,sys
for x in sys.path:
print x
print os.executable
and result is weird
C:\Users\devtool\.virtualenv\devenv\Scripts
C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg
C:\Python27\lib\site-packages\virtualenv-1.8.4-py2.7.egg
C:\Python27\lib\site-packages\pip-1.2.1-py2.7.egg
C:\Users\developer\.virtualenv\devenv\Lib\site-packages\django
C:\Windows\system32\python27.zip
C:\Python27\DLLs
C:\Python27\lib
C:\Python27\lib\plat-win
C:\Python27\lib\lib-tk
C:\Python27
C:\Python27\lib\site-packages
['C:\\Users\\developer\\.virtualenv\\devenv\\Lib\\site-packages\\django']
C:\Python27\python.exe
in fact it is just using base python install.
What is the point of using virtualenv?
i am getting errors with django, installed in virtualenv.
i can solve it, just need to rewrite django-admin.py to append to search path my virtualenv folder, but still what is need of virtualenv in this case.
another thing that i cant understand. In the python search path, there is a line
C:\Users\devtools\.virtualenv\devenv\Lib\site-packages\django
and when i use django-admin.py i get
Traceback (most recent call last):
File "C:\Users\devtools\.virtualenv\devenv\Scripts\django-admin.py", line 12, in module>
from django.core import management
ImportError: No module named django.core
but django folder is in the path
I have also faced the same issue few days before. From the base folder, you have to execute the following command.
C:\Users\devtools\.virtualenv\devenv> python Scripts\django-admin.py startproject myproj
virtualenv extends/overrides your system python environment with its paths prepended to the paths of the system python installation. You see, you .virtualenv site-packages are listed before the system site-packages, that's how it works.
The thing you have to keep in mind that activate patches your current command line environment, so you must run activate before running python code depending on your virtualenv.

Categories

Resources