So I am learning to use SublimeREPL, and I encounter a problem.
I have a main.py file, and in the same folder a timer.py. I write import statement in the main.py:
import timer
Then if I open
1) SublimeREPL --> Python --> Python--IPython, and transfer the code to the InteractiveConsole, I get error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<string>", line 1, in <module>
ImportError: No module named timer
2) SublimeREPL --> Python --> Python, and transfer the code to the REPL console, it runs as expected.
I wonder what is the reason?
This is because the sys.path doesn't contain the given directory. You can edit this through the code below
import os
import sys
sys.path.append(os.getcwd())
# os.getcwd() is the current directory, make sure it's the right one.
This will make it possible to import timer.py
Related
I have a strange problem after I moved an application to a different folder. I copied all files inside the old folder to the new directory and then tried to restart the application. However when I do so I get the error message:
Traceback (most recent call last):
File "bin/zeoserver", line 24, in <module>
import plone.recipe.zeoserver.ctl
File "/usr/local/Plone/buildout-cache/eggs/plone.recipe.zeoserver-1.3.1-py2.7.egg/plone/recipe/zeoserver/__init__.py", line 1, in <module>
import logging
File "/usr/local/Plone/Python-2.7/lib/python2.7/logging/__init__.py", line 26, in <module>
import sys, os, time, cStringIO, traceback, warnings, weakref, collections
ImportError: No module named time
This is particularly intriguing as time should be a pre-installed Python package. What is also interesting is that after renaming the old folder to xyz_old I cannot start the application from there either.
What could cause such an issue?
I am trying to add an external python library from a third party software into Spyder so I can work with it. I have already tried the following:
Adding library path containing .py files to Tools>PYTHONPATH manager
Synchronizing the path
Updating module names list through Tools>Update Module names list
However, when I try to import modules from this library I get two types of errors:
import easy
Traceback (most recent call last):
File "<ipython-input-2-685519d35f15>", line 1, in <module>
import easy
File "C:\Program Files (x86)\Plaxis\PLAXIS 2D\plxscripting\easy.py", line 24, in <module>
from .server import Server, InputProcessor
ValueError: Attempted relative import in non-package
The second type of error as follows:
from plxscripting.easy import *
Traceback (most recent call last):
File "<ipython-input-1-a40c101d3bb0>", line 1, in <module>
from plxscripting.easy import *
ImportError: No module named plxscripting.easy
I don't understand why Spyder is not recognizing these libraries. The path has been added and shows up on the manager. What constitutes a python module? Is it not just the .py file with module name prefix? Is not the path sufficient to work with the library through the IDE?
I have a python script which runs another python script and this latter script imports a module. It fails to do so and returns the following:
Traceback (most recent call last):
File "/some/path/script.py", line 13, in
import Autodock as AD
File "/some/path/to/module/Autodock.py", line 30, in
import BALL
File "/usr/lib/pymodules/python2.7/BALL.py", line 1, in
from BALLCore import *
ImportError: /usr/lib/pymodules/python2.7/BALLCore.so: undefined symbol: _ZN4BALL25FragmentDistanceCollectorclERNS_9CompositeE
However it gets loaded successfully when I just open the python interpreter and enter this:
>>> from BALLCore import *
Other scripts which also run /some/path/to/module/Autodock.py (which is the script importing the module) run successfully. What makes them successfully import the module from the same module-path?
I need to excuse myself for not sharing so much code, because I have no clue where to look. Any guidance would be appreciated.
Im trying to figured out this problem. Yesterday I installed PyScripter and since then, scripts doesnt work. When I run any script (in PyScripter or IDLE) and trying to "import arcpy", it gets this error:
import arcpy
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import arcpy
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 17, in <module>
from geoprocessing import gp
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\__init__.py", line 14, in <module>
from _base import *
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 14, in <module>
import arcgisscripting
File "C:\Python26\ArcGIS10.0\lib\arcgisscripting.py", line 81, in <module>
from RuntimeError import RuntimeError
ImportError: No module named RuntimeError
Have somebody any suggestion how to fix it?
Thanks to all very much!
Sounds like the module is not installed properly (or at all). To verify, do the following:
open a shell and start the python shell by typing python
(If this doesn't display an error, check that python is added to your system path or if it is even installed at all. But if you've used Python on said machine maybe system path issue)
enter the commmand help('modules')
review the list of modules that's returned to see whether arcpy is included
if not, then you may have to reinstall the module
I have a directory with two .py files in my C:\Python27\word_data called main.py and gethtml.py.
I want to import gethtml.py in my main.py, print def from that file, and I tried to do like this:
import gethtml
print gethtml.getHtmlText()
When I run this in a Python shell I get an error:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
execfile("word_rank/main.py")
File "word_rank/main.py", line 3, in <module>
import gethtml
ImportError: No module named gethtml
What am I missing?
You could check that the working directory for your python session is the directory containing your two python files. You can get Python to report the location of the current working directory as follows:
import os
print(os.getcwd())
Python will look in the current working directory (and in some directories in PATH) for the file you are trying to import. Not being able to find the file would give the error above.