I am trying to set up sleepy.mongoose, a mongoDB REST interface using the instructions here.
I am using windows 8, :( ...anyway... I have python 3.3.2 installed and it is accessible from the cmd prompt. I also have pymongo installed, when i enter help('modules') to python, pymongo is on the list of available modules!
But when I try to run python httpd.py from the sleepy.mongoose dir (thanks karthikr), I get an error:
C:\Users\Brook\Desktop\sleepy.mongoose>python httpd.py
Traceback (most recent call last):
File "httpd.py", line 1, in <module>
sleepymongoose/httpd.py
NameError: name 'sleepymongoose' is not defined
Now I tried actually cding into the proper dir, but I get this other error:
C:\Users\Brook\Desktop\sleepy.mongoose\sleepymongoose>python httpd.py
File "httpd.py", line 221
print "\n================================="
^
SyntaxError: invalid syntax
I have had the same problem with Python 2.7 on Windows. Considering 'httpd.py' wich contains only:
sleepymongoose/httpd.py
You need this command line to start it:
python sleepymongoose/httpd.py
You are using python 3 to run python 2 code. The syntax for print amongst other things has changed. Use Python 2 or a server which supports python 3.
Related
Something in my setup of my shell causes arbitrary strings like "krmpfl" or "u45g5svtJ7" to create a Python error:
$> krmpfl
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 28, in <module>
from CommandNotFound import CommandNotFound
File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in <module>
from CommandNotFound.db.db import SqliteDatabase
File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
I would expect bash (and not python!) to throw an error of the kind "Unknown command krmpfl. Did you mean...", but any non-recognized command is for some reason passed to python. I am confused.
Does anyone have an idea on how to debug this or how to move forward? I've tried type krmpfl but this (correctly) echoes bash: type: krmpfl: not found
My setup:
Win10 using Ubuntu 18.04 within WSL
ConEmu as a console
Bash-it
Python 3.8
Click (python package) installed to simplify creating commands
If your current shell function defines a function named command_not_found_handle, bash runs that for a non-existent command rather than immediately failing with a "command not found" error. In your case, that function exists and calls /usr/lib/command-not-found, which appears to be a Python script that tries to download (or at least suggest you download) a package with apt_pkg, but you don't have that Python module installed, which leads to the Python exception.
When calling a python script from within Pycharm my script runs successfully. However when I call the same script via my terminal I get an import error:
Macs-MacBook:src macuser$ python ./run_events.py
Traceback (most recent call last):
File "./run_events.py", line 3, in <module>
from functions import return_ga_data
File "/Users/macuser/PycharmProjects/ops-google-extract/src/functions.py", line 2, in <module>
import connect
File "/Users/macuser/PycharmProjects/ops-google-extract/src/connect.py", line 4, in <module>
from oauth2client.service_account import ServiceAccountCredentials
ImportError: cannot import name 'ServiceAccountCredentials'
I am not using an environment. Also I'm using python 3.7.
All my python scripts are in the same directory. My terminal's pwd is the same directory.
Tried:
Tried calling the script with python3 ./run_events.py but I get the same result.
Per an SO post about paths I added this to the top of connect.py:
import sys
sys.path.append('/Users/macuser/PycharmProjects/ops-google-extract/src/functions.py')
I still got the same result.
Why can I run the file without an import error from within my IDE but not via the terminal when using ./run_events.py?
Do you have python 2 installed as well? Type python --version in the terminal and see what you get? My guess is Pycharm might be configured to use python 3 while your default python in terminal is python 2, so your python 2 is lacking those modules that was installed for python 3. So when you execute your script in the terminal it's using python 2. If that's the case you can try,
py -3 ./myscript.py
I am a beginner in Python and am learning via online tutorials. On Study Drill #6 for example 15 on this page, I'm trying to open up the 'ex15_sample.txt' file that I have created and exists.
This is what it says to do:
Start 'python' to start the Python shell, and use 'open' from the prompt just like in this program. Notice how you can open files and run 'read' on them from within 'python'?
In the command prompt, I entered python to start the Python shell and have tried typing in the following, which threw me an error:
open(ex15_sample.txt)
The error I get is:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'ex15_sample' is not defined
ex15_sample.txt is a file that exists in the same folder. How am I supposed to use open or any other command from the prompt? I am running Python 2.7.8 on Powershell, by the way.
The first argument of open is a string containing the filename.
Just put file name in Quotation Mark:
f = open('ex15_sample.txt')
I am trying to execute "import android" command on the python shell. It gives error like this :
>>> **import android**
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
import android
File ".\android.py", line 51
print result['error']
^
I'm having python 3.3.2 installed on the PC (windows 7) and have android.py (SL4A) available in the python directory on my system and the system path also contains python.
Plz help in resolving this error.
Print changed from a statement to a function on Python 3. And the module(android) you're trying to import is written for Python 2.
You should either use a Python 2 interpreter, or find(or make) that module compatible with Python 3.
I'm trying to port)cwiid from python 2.7 to 3.2.
It uses a lot of deprecated stuff so I have to change a lot of stuff in order to have it work with 3.2. Right now I'm stuck because of a load error. With a python 3.2 environment and the library installed to the package repo I do:
prompt: echo "import cwiid" | python -
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (PyInit_cwiid)
Besides blind searching in the source code, where does python expect the PyInit_cwiid method?
In the source code for example there is the py_plugin.c which contains a py_init method.