from ghost import Ghost
running it from IDLE works; but if I run a py file with only this line of code it get this error.
Traceback (most recent call last):
File "C:\Users\Teo1\Desktop\sub\ghost.py", line 1, in <module>
from ghost import Ghost
File "C:\Users\Teo1\Desktop\sub\ghost.py", line 1, in <module>
from ghost import Ghost
ImportError: cannot import name Ghost
It may seem a stupid question, but what it's so simple that I can't find my error.
I'm using ghost.py with PySide, both installed with pip.
Your program is trying to import itself, since the first module ghost it finds is your ghost.py.
Renaming your program will fix this problem.
Related
I have pygame and numpy in the same folder. I can import pygame, but I can only import numpy in the terminal, not even in the IDLE. If I try to import numpy anywhere else, I get this message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
I can also still import pygame into the terminal. Also, python in the terminal is version 3.7.5, but in the IDLE it's 3.6.6. Not sure if that's related.
All of my modules are in the default path folder.
I'm having issues running ortools on Linux. I downloaded it from google's site (https://developers.google.com/optimization/) and installed it using "make install," but when I go to use it in python I get the following:
Traceback (most recent call last):
File "regular.py", line 42, in <module>
from ortools.constraint_solver import pywrapcp
File "/home/m3/summer/ortools_examples/examples/python/ortools.py", line 2, in <module>
ImportError: No module named linear_solver
It looks like despite installing ortools, its still not in my python path correctly, so when I call it in the file, it doesn't find anything and returns an error, right? Any advice on how to solve this?
I run linux mint 17.2 XCFE on my computer.
My issue is nearly identical to the one found in this thread, except I tried all of the solutions offered and none worked. It's worth noting that as a result of me trying to fiddle with python, my machine now runs 2.7.8 and the venv runs 2.7.6, which is easy to fix but might be relevant.
I also consulted this and this, and tried changing the name of file called operator and a different virtualenv command as suggested in those, but nothing worked. (Note: I then changed the name of that file back to operator just because since that wasn't the problem I'd rather not mess with it).
When I try to run a very simple script for flask newbs I keep encountering the same error.
(venv)joshua#joshua-ThinkPad-Edge-E430 ~/website/projects/helloapp $ python hello.py
Traceback (most recent call last):
File "hello.py", line 1, in <module>
from flask import Flask
File "/home/joshua/website/projects/helloapp/venv/lib/python2.7/site-packages/flask/__init__.py", line 21, in <module>
from .app import Flask, Request, Response
File "/home/joshua/website/projects/helloapp/venv/lib/python2.7/site-packages/flask/app.py", line 26, in <module>
from . import json
File "/home/joshua/website/projects/helloapp/venv/lib/python2.7/site-packages/flask/json.py", line 25, in <module>
from itsdangerous import json as _json
File "/home/joshua/website/projects/helloapp/venv/lib/python2.7/site-packages/itsdangerous.py", line 14, in <module>
import hmac
File "/home/joshua/anaconda/lib/python2.7/hmac.py", line 8, in <module>
from operator import _compare_digest as compare_digest
ImportError: cannot import name _compare_digest
I have been trying to figure out a solution on my own for hours but I've had no luck. I think it might have to do with Anaconda but I'm not sure what could be done if that's the case.
As it turns out the issue was that the hmac.py file had a reference to a method that it appears no longer existed. I disabled that reference with '#' (just incase it turns out it was important) and it started working.
For some reason, anytime I try to import a python library, a particular old error message keeps popping up.
However, everything works fine when working with shell.
I know this is not a real programming question, but I'm stuck and would appreciate any help.
Any ideas on how to fix this?
Error message
>>> import nltk
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import nltk
File "C:\Python27\lib\site-packages\nltk\__init__.py", line 91, in <module>
from internals import config_java
File "C:\Python27\lib\site-packages\nltk\internals.py", line 22, in <module>
except ImportError: from xml.etree import ElementTree
ImportError: No module named etree
Does "C:\Python27\lib\xml\etree\ElementTree.py" exist in your computer?
Since IDLE and shell behaves differently, you may try the two lines in IDLE and Shell:
import sys
sys.path
Then check the difference of env path
I just installed Selenium (from source) for Python 2.7.
When I try to import selenium, I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\selenium-2.25.0-py2.7.egg\selenium\__init__.py", line 16, in <module>
from .selenium import selenium
File "C:\Python27\lib\site-packages\selenium-2.25.0-py2.7.egg\selenium\selenium.py", line 19, in <module>
import http.client
ImportError: No module named http.client
What could be causing this? If I remember correctly, http.client is a python 3 module. Why is selenium trying to import it?
Thanks to the help of DSM, I figured it out. Because I had previously ran setup.py with a python3 executable by accident, the selenium build folder was populated with 2to3 converted code. When I later ran python27 setup.py install it ended up using the same build folder for the installation without overwriting its content. I ended up deleting the build folder and trying again, and it works.