tensorflow-syntaxnet: Where are sentence_pb2 and gen_parser_ops? - python

I cannot import these two python files from syntaxnet and I cannot find them either. Does anyone know how to solve this issue? Thanks!
from syntaxnet.ops import gen_parser_ops
from syntaxnet import sentence_pb2

Those two are imported in syntaxnet/syntaxnet/conll2tree.py. You can get their locations by adding lines like below in conll2tree.py:
import os
print os.path.realpath(gen_parser_ops.__file__)
and then run the demo.sh as in the installation guide.

gen_parser_ops file is present under bazel-out/local-opt/genfiles/syntaxnet/ops/gen_parser_ops.py
sentence pb2 file is present in bazel-out/local-opt/genfiles/syntaxnet/sentence_pb2.py.
I found these files in my linux machine (ubuntu) using the find command:
sudo find ~/ -type f -name "gen_parser_ops*"
sudo find ~/ -type f -name "sentence_pb2*"

Related

Forgot path to module

I made a script called sm on a linux-os, which I want to update from python 3.6 to 3.9. But unfortunately I forgot the path to this file. I tried it with the command "locate sm.py" but it showed me thousands of things, where the name was something like the file name "sm.py", and I don't want to read through it. So does anyone know how to find this file more precisely than my locate-command?
try this in shell
find / -name "sm" -depth -exec echo {} \;

Executing all files inside a folder in Python

I have 20 Python files which is stored inside a directory in ubuntu 14.04 like 1.py, 2.py, 3.py , 4.py soon
i have execute these files by "python 1.py", "python 2.py" soon for 20 times.
is their a way to execute all python files inside a folder by single command ?
find . -maxdepth 1 -name "*.py" -exec python3 {} \;
for F in $(/bin/ls *.py); do ./$F; done
You can use any bash construct directly from the command line, like this for loop. I also force /bin/ls to make sure to bypass any alias you might have set.
Use a loop inside the folder:
#!/bin/bash
for script in $(ls); do
python $script
done
You can try with the library glob.
First install the glob lybrary.
Then import it:
import glob
Then use a for loop to iterate through all files:
for fileName in glob.glob('*.py'):
#do something, for example var1 = filename
The * is used to open them all.
More information here: https://docs.python.org/2/library/glob.html

Find path of python program in execution

In my terminal, I can see a python program in execution:
python3 app.py
where can I find app.py?
I've tried to look in the /proc/$pid/exe but links to the python interpreter.
I have many app.py programs in my system, I want to find out exactly which is in execution with that pid.
i ran a short test on my machine and came up with this... maybe it helps:
find the process id PID of the job in question:
$ ps -u $USER -o pid,cmd | grep app.py
the PID will be in the first column. assign this number to the variable PID.
find the current working directory of that job:
$ ls -l /proc/$PID/cwd
(for more info: cat $ cat /proc/$PID/environ)
your app.py file will be in this directory.
check the file
/proc/[PID]/environ
There is PWD variable contains full path of the directory containing the executable file.
If you are on Mac Os X please try using:
sudo find / -type f -fstype local -iname "app.py"
If you are not on Mac Os X you can use:
sudo find / -mount -type f -iname "app.py"
The find command will start from your root folder and search recursively for all the files called "app.py" (case insensitive).

no module name pip : after changing permission of python folder

here is what i did before i messed up everything :
i tried to install a package using pip3 , after a long time the download finished and suddenly the error about permission came up because i forgot to use sudo at first and because I didn't want to download the packages again and didn't know where is the pip cache folder is , I did a very stupid thing i changed the permission of the entire python folder in the /usr/bin/ to install package without sudo , after this i tried this :
pip3 install tensorflow
File "/usr/bin/pip3", line 7, in <module>
from pip import main
ImportError: No module named 'pip'
i got these damn error ,
can anybody help me fix this ?
Edit :
here is my sequence of the command i used :
1 - pip3 install tensorflow
-- the error came up
2 - sudo find /usr/lib/python3.5/ -type d -exec chmod 766 {} \;
3 - sudo find /usr/lib/python3.5/ -type f -exec chmod 766 {} \;
First, and foremost, I consider your approach quite unwise. You have now changed the permissions of all files and directories for the owner, the group, and others.
In principle you just needed to ensure that pip3 (by extension, your user-account) would be able write files and directories in a directory owned by root (presumably /usr/lib/python3.5/site-packages). You could have accomplished this by:
sudo chmod o+w /usr/lib/python3.5/site-packages
Alternatively you could have changed the ownership of this folder. IMPORTANT: when doing this kind of thing, be sure to know what you are doing, and don't forget to change everything back as soon as possible. Things can be broken, and security issues can be created.
Now as to a solution to your problem. You have now given the directories the following permissions -rwxrw-rw- (6 = 4 (read) + 2 (write)). However for users, and programs executed on its behalf, to do anything to/from a directory they need the right to execute. For this you should have used 5 instead of 6 (5 = 4 (read) + 1 (execute)). To correct:
sudo find /usr/lib/python3.5/ -type d -exec chmod 755 {} \;
Then, I think that for Python to correctly load compiled libraries (shared-objects or .so files) they should also have these permissions. Judging from my own Python directory I would probably do:
sudo find /usr/lib/python3.5/ -type f -exec chmod 644 {} \;
sudo find /usr/lib/python3.5/ -type f -iname '*.so' -exec chmod 755 {} \;
to set everything back to it's original state.
P.S. I am no expert in pip, so I have no idea what the protocol is to avoid pip from re-downloading upon retrying a failed installation.

Django import error - no module named django.conf.urls.defaults

I am trying to run statsd/graphite which uses django 1.6.
While accessing graphite URL, I get django module error
File "/opt/graphite/webapp/graphite/urls.py", line 15, in
from django.conf.urls.defaults import *
ImportError: No module named defaults
However, I do not find defaults django package inside /Library/Python/2.7/site-packages/django/conf/urls/
Please help fixing this issue.
django.conf.urls.defaults has been removed in Django 1.6. If the problem was in your own code, you would fix it by changing the import to
from django.conf.urls import patterns, url, include
However, in your case the problem is in a third party app, graphite. The issue has been fixed in graphite's master branch and version 0.9.14+.
In Django 1.8+ you can remove patterns from the import, and use a list of url()s instead.
from django.conf.urls import url, include
If for some reason you don't want to downgrade to Django 1.5.x or upgrade Graphite then you can apply the fix to your older Graphite with:
find ./ -type f -exec sed -i -e 's/from\ django\.conf\.urls\.defaults\ import\ \*/from\ django\.conf\.urls\ import\ \*/g' {} \;
..in your <graphite_dir>/webapp/graphite dir.
This helped me with my Graphite 0.9.12 and Django 1.7(.5).
(I also had to do:
find ./ -type f -exec sed -i -e 's/mimetype\=/content_type\=/g' {} \;
find ./ -type f -exec sed -i -e 's/content_type\=mimetype/content_type\=content_type/g' {} \;
..later on as after I managed to start Graphite some of its features didn't work. Now they work for me but YMMV.)
go to the file location where you have installed python.
open cmd on that path and then install django with command >> pip install django
Then cross check on python shell with import django(which should do nothing)
or simply use the command >> python -m django --version
it will simply give you version
enter image description here
enter image description here

Categories