I'm at exercise 50 of lpthw this is the link.
And after having downloaded the lpthw.web framework in a very messy way.
I continued the exercise by writing a .py file.
import web
urls = ('/', 'index')
app = web.application(urls, globals())
class index:
def GET(self):
greeting = "Hello World"
return greeting
if __name__ == "__main__":
app.run()
but i got this error:
Traceback (most recent call last):
File "bin\app.py", line 1, in <module>
import web
File "c:\Python31\lib\site-packages\web\__init__.py", line 14, in <module>
import utils, db, net, wsgi, http, webapi, httpserver, debugerror
ImportError: No module named utils
What is the problem caused by,
I suspect it is the very messy way with wich I installed lpthw.web (I got a lot of errors, but tried multiple ways multiple times.)
Thank you in advance!
If anybody needs more info comment so I can edit.
I think you forgot to read the setup instructions. This learning guide is not python3 compatible:
Exercise 0: The Setup
You should follow these instructions as exactly as possible. For
example, Mac OSX computers already have Python 2, so do not install
Python 3 (or any Python).
Make sure you install Python 2 not Python 3.
Warnings For Beginners
A programmer may try to get you to install Python 3 and learn that. You should tell them, "When all of the python code on your computer is Python 3, then I'll try to learn it." That should keep them busy for about 10 years.
Remove python3 from your system and install python2.7 to allow this tutorial to work when you install suggested packages.
Otherwise, find another tutorial that is using examples from libararies that are python3 compatable. Not everything is updated as of right now. Many people stick to python2.7 for this reason.
As the tutorial state, you can try installing using easy_install or pip from the command line it would be easy_install lpthw.web or pip install lpthw.web
Also note that you need to properly reference application
this app = application(urls, globals()) should be
app = web.application(urls, globals())
note the ^^^ part.
Also if you are interested in python micro-web-frameworks I recommend bottle.py, it doesn't need to be installed its just a single python file called bottle.py
Update
I managed to recreate the problem using python3, so jdi was right, the problem here is that python3 isn't backwards compatible with python2, some python2 complaint applications won't properly run under python3 and vice-versa.
In this case python3 doesn't seem to support relative imports within package, did find this http://www.python.org/dev/peps/pep-0328/ which was kind of interesting.
exert from the pep:
For the second problem, it is proposed that all import statements be absolute by default (searching sys.path only) with special syntax (leading dots) for accessing package-relative imports.
so lpthw.web tries to import relative packages but it simply can't.
which is why we get ImportError: No module named utils since utils is relative module within the package.
even if it could loaded it, it will stumble with other non-backwards compatibility issues, just trying to import utils within the package we get
>>> import utils
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "utils.py", line 75
except KeyError, k:
^
SyntaxError: invalid syntax
which is related to this pep http://www.python.org/dev/peps/pep-3110/ which states different syntax to the except statement.
As you can see it will be a major hurdle trying to migrate this package to python3 so much so thats its better to leave it to the developers, this goes for the many many packages out there, why is python3 so different from python2, well mainly because they wanted to patch the language as much as possible ...
For the time being stick to python2, eventually most packages will be migrated to python3.
Related
I downloaded the Podio API for Python and after something like ten tries I got it installed, by then I had already downloaded it 3 times from different sources, and when I got errors later (since apparantly I had downloaded and installed the Python 2-version) I was very confused and wanted to simply undo everything and install it correctly without all the crap. I tried uninstalling but it didn't work (partly I think because I don't know which method of installing it was actually successful, it just worked all of a sudden), so I just deleted everything and hoped that would at least disable it. After doing that I installed again it by typing this (relevant since I someone told me the pip-version wasn't updated, but the github-version was, and told me to type this instead. I don't understand the difference since it still says 'pip install') in the CMD:
pip install -e git+https://github.com/podio/podio-py.git#egg=podio-py
now I get this error:
from pypodio2 import OAuthClient
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from pypodio2 import OAuthClient
ImportError: cannot import name 'OAuthClient'
What causes the problem? Two days of issues with this API.
OAuthClient is accessible via pypodio2.api. Change your import statement to:
from pypodio2.api import OAuthClient
client = OAuthClient('api_key', 'api_secret', 'login', 'password')
I'm getting the error
Traceback (most recent call last):
File "ghs.py", line 1, in <module>
import stdio
ImportError: No module named stdio
When I try to run my script. I can run my script on other machines just fine. I have installed python using homebrew. And I've tried everything I can think of to get it to recognize my modules! I've uninstalled and reinstalled using brew. I've tried changing the path (though I don't fully understand this). I get no issues using brew doctor.
I've also tried using a python virtual environment but to no avail.
Any ideas on how to fix this issue or else 'start fresh' from a fresh version of python?
When you import a module, Python looks for it at the directory your code is, and the directory in which the built-in libraries are (C:\Users\pc\AppData\Local\Programs\Python\Python35-32\Lib in my case, I'm using Windows 10 and Python 3.5). If it can't find it, it raises ImportError.
I couldn't find a module named stdio in my computer. I also know some C++ and as far as I know, stdio is the library for inputs and outputs(prints). In python, there is no need to import such a library.
You can use try,except statement to test if your code works without importing the module like this.
try:
import stdio
except:
#rest of your code goes here
You will need to indent your whole code however this can be done easily with a text editor in which you can edit more than one line at a time.
Whenever I try to import a file into python, it comes up with this error(or similar):
Traceback (most recent call last):
File "C:/Python33/My Files/username save.py", line 1, in <module>
import keyring.py
ImportError: No module named 'keyring'
I am trying to create a password storing program, and I was looking up for good ways to keep passwords secure, and someone said use import keyring, so I did, except, it never works. I must be doing something wrong, but whenever I look anything up for python, it never works out for me. It's almost as if loads have things have been changed over the years.
and idea's?
The keyring module is not part of the Python standard library. You need to install it first. Installation instructions are included.
Once installed, use import keyring, not import keyring.py; the latter means import the py module from the keyring package. Python imports should use just the name of the module, so not the filename with extension. Python can import code from more than just .py python files.
I was getting the same error "ModuleNotFoundError: No module named 'keyring'". And after installing this module pip install keyring, the same error occured with another module name. Then I came to the conclusion that it is the fact that the VSCode is not able to connect to my venv, even after setting the Python Itereptor. Press CTRL + SHIFT + P, and then type Python: Select Interceptor, and select your venv, if you want to set this.
To fix the issue, I had to force the VSCode to use the .venv I created, and luckily there is a dropdown to do that, on the top right corner as in the preceeding image. Click ont the Python version, and then you will be able to select your virtual environment.
Now it will take the modules from your virtual environment.
I have been trying to import modules into Ninja IDE for python. These are modules that I have working on the terminal (numpy, scipy, scitools, matplotlib, and mpl_toolkits), but will not run correctly in Ninja.
First I was only getting the message No module named ____. I checked sys.path and found that the path was within the application
/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7 was a typical path. I tried changing the path,but it doesn't seem to do anything to sys.path even after restarting the ide.
But I wanted the path to refer to where the modules are stored (which is /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages). I was able to get numpy and scipy to work as well as parts of mpl_toolkits by adding the contents of my path to the folders that sys.path gave. However, I still can't get fully functioning modules within the ninja ide interpreter. I'll give some examples below of what happens when I import certain modules.
import matplotlib.pyplot
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/matplotlib/__init__.py", line 106, in <module>
ImportError: No module named sysconfig
import mpl_toolkits
from mpl_toolkits.mplot3d import axes3d
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/mpl_toolkits/mplot3d/__init__.py", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/mpl_toolkits/mplot3d/axes3d.py", line 14, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/matplotlib/__init__.py", line 106, in <module>
ImportError: No module named sysconfig
Thanks for the help. I apologize, I am very new to programming, but I did put in about a day and a half of research before posting here.
That's strange as the sysconfig module is a part of Python 2.7 standard library.
Are you sure that Ninja is using the right Python version? Try running:
import sys
print sys.version_info
from Ninja, to see which Python version it is actually using.
I know this question is a few months old, but I wanted to post my solution in case others find it useful. I had a very similar problem, and had a lot of trouble finding a quick workable solution anywhere.
My somewhat roundabout solution was to simply create a virtualenv folder with the version of numpy I wanted, and then pointed the "virtualenv" property for NinjaIDE project to that folder. I restarted NinjaIDE and boom, instantly worked.
To set the virtualenv property for your project via the GUI, go to the Project menu:
Project > Open Project Properties > Project Execution,
and you should see a variable called "Virtualenv Folder". Point that to the folder for your virtualenv, and it should work. (May need to restart NinjaIDE.) This worked for me, NinjaIDE version 2.2 under Ubuntu 12.04.
One quick note: I actually didn't use virtualenv exactly -- I had to use a "conda env," since I am using the Anaconda distribution, and apparently it is not well-tested with virtualenv yet. (I actually got a warning when I went to easy_install virtualenv. Hadn't seen that before.)
Either way, this stackoverflow question has some nice pointers to virtualenv tutorials: Comprehensive beginner's virtualenv tutorial?
Good luck!
I was having a similar problem trying to import a module from /home/paul/lib/python using the console of the Ninja-IDE. I found out that /home/paul/lib/python didn't appear in syspath when checking in the console of the Ninja-IDE. But it did in the terminal!
By starting the Ninja-IDE from the terminal, /home/paul/lib/python was in syspath when checking in the console of the Ninja-IDE. I was now able to import the module I needed.
I hope this might be of some help. If not to ebris1 than maybe to others.
I am debugging a python script. I have one section that is throwing IndexErrors, and I want to use pdb to find out why. Here is my script:
try:
# do stuff that throws an IndexError
except IndexError:
import pdb; pdb.set_trace()
When I run the script, it crashes on the line import pdb; pdb.set_trace(). The traceback I get:
Traceback (most recent call last):
File "myfile.py", line 113, in <module>
import pdb; pdb.set_trace()
File "/usr/lib/python2.7/pdb.py", line 10, in <module>
import bdb
File "/usr/lib/python2.7/bdb.py", line 3, in <module>
import fnmatch
ImportError: No module named fnmatch
import pdb, import bdb, and import fnamatch all work without error in the python interpreter. I don't even know where to start with this one.
UPDATE June 8 2016:
This question was recently brought to my attention again. I'm afraid I don't remember this at all, what the resolution was, or even what I was working on. I am not sure why I neglected to respond to the (good questions!) comments. At this point I assume it was resolved - I have successfully used pdb in the last 4 years :D
What I can say at this point: I was most likely using Ubuntu (probably 12.04).
I likely would have been using a virtualenv. Or at least thought I was using a virtualenv. I would expect stack traces to reference something like /home/foo/.virtualenvs/bar/..., not /usr/lib/python2.7.
It might be a reach, but I recall pip didn't always use --no-site-packages by default. Perhaps something installed on the system python conflicted with something in my virtualenv. Absolute paths somewhere, or messing with PYTHONPATH in some way?
This starts to be a reach, but I'm having trouble imagining what scenario I got myself into. This at least sounds plausible to me:
I had package X installed in the system python.
I created a virtualenv without --no-site-packages, thus pulling X into the virtualenv.
I installed Y in the virtualenv, which conflicted with X.
I was running my script in terminal A, in the virtualenv, and encountered the error.
I opened terminal B, forgot to activate the virtualenv, and thus ended up using a different interpreter (credit to #DSM for this one).
Without the virtualenv (and the hypothetical conflict), import pdb works fine.
I'm sorry this question appears to draw continued interest, and I only have hunches and guesses. If you encounter this today, my suggestion would be to check the stack trace locations are what you expect. If that's the case, check that any files referenced there actually exist, and appear to be intact.
Barring that, I would try a fresh virtualenv.
If you experience this problem and find a fix, please post it! I'll be happy to accept your answer.