docopt in python is giving me issues - python

I have a set of three programs that I am trying to combine into one. They all work individually, but I am having issues when trying to get them to work together. The issue I am currently having is with the first section of code:
import os
import sys
from contextlib import closing
import colorama # $ pip install colorama
import docopt # $ pip install docopt
import socks # $ pip install PySocks
import stem.process # $ pip install stem
from sockshandler import SocksiPyHandler # see pysocks repository
from stem.util import term
try:
import urllib2
except ImportError: # Python 3
import urllib.request as urllib2
args = docopt.docopt(__doc__, version='0.2')
colorama.init(strip=not (sys.stdout.isatty() or args['--color']))
When I run the program, I get this error:
Traceback (most recent call last):
File "cilantro.py", line 34, in <module>
args = docopt.docopt(__doc__, version='0.2')
File "C:\Python34\lib\site-packages\docopt.py", line 558, in docopt
DocoptExit.usage = printable_usage(doc)
File "C:\Python34\lib\site-packages\docopt.py", line 468, in printable_usage
raise DocoptLanguageError('"usage:" (case-insensitive) not found.')
docopt.DocoptLanguageError: "usage:" (case-insensitive) not found.
Why am I getting this error message? The same code works fine in the original program.

When using docopt you need to write a __doc__ string for your script. docopt parses this string to work out how to handle the command line options and arguments.
To fix this, and something like the following text above your "import os" (so it's the first thing in the file):
"""
Name.
Describe what this script does
Usage:
name <firstarg>
name --countdown
name sillycommand <SILLYNESS>
name -h | --help
Options:
--countdown display a count down
"""
More details on what to put in this usage string can be found at the docopt documentation, http://docopt.org/

Related

ModuleNotFoundError: No module named 'data_receiver'

when I go to run my program, I keep receiving the error message below:
pi#navio:~/cloudapp-raspi $ sudo python3 app.py
Traceback (most recent call last):
File "app.py", line 7, in <module>
from data_receiver import DataReceiver
ModuleNotFoundError: No module named 'data_receiver'
however, when I go in the app.py file (see below), I clearly have it being imported.
import logging, time, argparse, configparser, sys
import socket, os, signal, psutil, data_receiver
from subprocess import Popen
from drone import Drone
from connection_watchdog import ConnectionWatchdog
from data_receiver import DataReceiver
from utils import Utils
data_receiver is not a standard python package. If you are installing it from a third party source using a package manager (like pip), be sure to install it globally, i.e., something like sudo -H pip install <package_name>.
Otherwise, if you have a data_receiver.py in your system, make sure to put it in the same directory as your app.py.

Backward compatibility with Modernize (Python2 to Python3) fails

I have a simple sample script written in python2. Since we are migrating to python3, I am trying to get familiar with the tools that ae present. The modernize tool, helps me to achieve a python3 code. I run it, I get the result expected.
However, modernize promises backward compatibility, I expect the newly generated code to run in python2 as well.
While running with python2 Interpreter, I face issues as shown below:
Eg:
Sample.py
import Queue
from urllib2 import urlopen
def greet(name):
print 'Hello',
print name
print "What's your name?",
name = raw_input()
greet(name)
From the directory on the commandline
python-modernize -w Sample.py
New Sample.py:
from __future__ import absolute_import
from __future__ import print_function
import six.moves.queue
from six.moves.urllib.request import urlopen
from six.moves import input
def greet(name):
print('Hello', end=' ')
print(name)
print("What's your name?", end=' ')
name = input()
greet(name)
I run the new script from the command line. Produces correct results.
py Sample.py
However, since it is backward compatible, when I do the following I get errors:
C:\Python27\python.exe Sample.py
Traceback (most recent call last):
File "Sample.py", line 3, in <module>
import six.moves.queue
ImportError: No module named six.moves.queue
Should the new script be modified again? Is modernize not fully backward compatible?
Please let me know
Did you install the six module ?
pip install six
https://pypi.org/project/six/
The answer for this is on the same regard as pip installing libraries in different versions. I was installing the library in python3. So now I managed to get it done on python2. Refer here
PythonDocumentation

Why am I getting this ImportError when trying to import docx in the Terminal?

I'm learning Python at the moment, and after installing the docx module, I keep getting this error when trying to import it in the Terminal:
import docx
Traceback (most recent call last):
File "", line 1, in
File "/Users/trevorstathatos/Library/Python/3.10/lib/python/site-packages/docx/init.py", line 14, in
from docx.parts.document import DocumentPart
File "/Users/trevorstathatos/Library/Python/3.10/lib/python/site-packages/docx/parts/document.py", line 7, in
from docx.document import Document
File "/Users/trevorstathatos/Library/Python/3.10/lib/python/site-packages/docx/document.py", line 10, in
from docx.section import Section, Sections
File "/Users/trevorstathatos/Library/Python/3.10/lib/python/site-packages/docx/section.py", line 7, in
from collections import Sequence
ImportError: cannot import name 'Sequence' from 'collections' (/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/init.py)
When trying to import it to my Mu Editor, I get this error:
import docx
~/Library/Application Support/mu/mu_venv-38-20211212-105811/lib/python3.8/site-packages/docx.py in
28 TAGS = {}
29
---> 30 from exceptions import PendingDeprecationWarning
31 from warnings import warn
32
ModuleNotFoundError: No module named 'exceptions'
Can someone please help me figure out how to fix this problem? Thanks.
I have readed on internet and a solution may be:
$ pip install python-docx
#instead of pip install docx
(for python 3.x)
Please try this and tell me if works
Link: https://flutterq.com/solved-import-no-module-named-exceptions/
Are you using the most recent version of python-docx? (currently 0.8.11). I found that when I used 0.8.10 python couldn't find all the modules.
You can use where python command in cmd to find the path that python is installed in. then you can use this command -
[python path] -m pip install python-docx
$ pip install python-docx
this worked for me.

ModuleNotFoundError: No module named 'googlemaps' - though googlemaps installed

I am running an app.py which imports googlemaps as
import googlemaps
But when I do a pip list, it lists googlemaps as
googlemaps 3.0.2
When I run the app,
Traceback (most recent call last):
File "app.py", line 40, in <module>
import googlemaps
ModuleNotFoundError: No module named 'googlemaps'
I am on Windows, Python 3.6.0
In order to be sure. that pip and your script use the same python version I suggest to call following commands from the same terminal window.
python3 -m pip freeze | grep -i googlemaps
python3 -c "import sys ; print(sys.exewutable)"
python3 -c "import sys ; print("\n".join(sys.path))"
Try even following line to prove that googlemaps is installed if not being called from your app
python3 -c "import googlemaps"
and
python3 app.py
If you do not call your app directly with python, then tell us how you start the app. This different way of calling might be why it is not pointing to the same python version / virtualenv than the one where you installed googlemaps
If you do not know how the app is exactly started (e.g. started by a web server or similar), then I suggest you add following lines to app.py
before the import line that fails.
import os, sys
# the next two l
with open(os.expanduser("~/debug.txt", "w") as fout:
fout.write("EXE: %s\n" % sys.executable)
fout.write("PATH:\n" + ("\n".join(sys.path)))
This should create a file named debug.txt,
that you can inspect

Tensorboard cannot import name `run_main`

Ever since I have updated to TensorFlow v1.4, I have not been able to run TensorBoard. Originally I was getting a problem related to flags (as I posted about here). In fact, I reinstalled TensorFlow with the understanding that a fix was in, but now I am getting this error instead:
Traceback (most recent call last):
File "/opt/python/3.6.3/bin/tensorboard", line 7, in <module>
from tensorboard.main import run_main
ImportError: cannot import name 'run_main'
I am getting this error regardless of whether I provide a log directory. What is the fix and what can I do to investigate?
I am fairly new to the Tensorflow ecoysystem. What I tried to do was open the file referenced above /opt/python/3.6.3/bin/tensorboard. I saw the following:
#!/opt/python/3.6.3/bin/python3.6
# -*- coding: utf-8 -*-
import re
import sys
from tensorboard.main import run_main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(run_main())
I looked at tensorboard.main where I saw nothing named run_main but I did see a def main so I tried changing the import run_main and run_main() to main but that led me back to the flags error. What am I doing wrong?
From here https://github.com/tensorflow/tensorboard/issues/812
pip install tb-nightly
It indicates the following there
If you're building TensorFlow from source please pip install tb-nightly.

Categories

Resources