$ bin/python src/app/utils/loader.py newTasks checkForStuff
Traceback (most recent call last):
File "bin/python", line 135, in <module>
execfile(__file__)
File "src/app/utils/loader.py", line 154, in <module>
module = __import__(args.module)
ImportError: No module named newTasks
from the following loader.py:
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Runs python')
parser.add_argument('module', metavar='module', help="the target module")
args = parser.parse_args()
module = __import__(args.module)
newTasks.py is in the same directory as loader.py. It works on my dev box, I did an svn export to staging and the above happened. Any pointers?
Only material difference I can work out is this time I'm running out of virtualenv.
EDIT:
I changed the command line to:
$ bin/python src/app/utils/loader.py utils.newTasks checkForStuff
and the module was found ok. But my next command is to call one of the module functions checkForStuff:
parser.add_argument('func',metavar='function', help="the target function name")
...
func_param = getattr(module,args.func)
and now it cannot find the function?
Traceback (most recent call last):
File "bin/python", line 135, in <module>
execfile(__file__)
File "src/app/utils/loader.py", line 156, in <module>
func_param = getattr(module,args.func)
AttributeError: 'module' object has no attribute 'checkForStuff'
If I go into bin/python:
>>> import utils.newTasks as nt
>>> nt.checkForStuff
<function checkForStuff at 0x29b2f50>
This is annoying!
bin/python is not the python binary on your staging machine. Check whether it inserts the scripts directory into sys.path as ordinary python does.
Related
I try to create desktop application with Electron.js and I need use some python packages in this application. I use python-bridge to run python codes in node.js. Now I can run python codes in node.js. But I need to add some python packages in it.
First, I created a python environment and installed some packages in it. I activated virtual environment then ran 'npm start' in it. This worked.
But I think this is not good idea for a desktop application. Because I won't be able to use this method when the app is released.
Also we have another way. When I read the docs about python-bridge, I saw this solution. But I can't use it. It doesn't see my python packages yet.
var python = pythonBridge({
env: {PYTHONPATH: '/foo/bar'}
});
This is js code in my main.js file to set python-bridge
const pythonBridge = require('python-bridge')
let python = pythonBridge({
// python: 'python3',
env: {
PYTHONPATH: 'venv'
}
});
and continues with these lines
python.ex`import pandas as pd`
python.ex`
def read_data():
return pd.read_excel('data.xlsx').to_json()
`
python`read_data()`.then(df => console.log(df))
python.end();
This error occurs when I run npm start
Unhandled rejection Error: Traceback (most recent call last):
File "C:\Users\hasan.ismayilov\projects\other\ElectronJS\firstTry\node_modules\python-bridge\node_python_bridge.py", line 101, in <module>
_exec(_compile(data['code'], '<input>', 'exec'), _locals)
File "<input>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
Unhandled rejection Error: Traceback (most recent call last):
File "C:\Users\hasan.ismayilov\projects\other\ElectronJS\firstTry\node_modules\python-bridge\node_python_bridge.py", line 104, in <module>
value = eval(_compile(data['code'], '<input>', 'eval'), _locals)
File "<input>", line 1, in <module>
File "<input>", line 2, in read_data
NameError: name 'pd' is not defined
at ChildProcess.onMessage (C:\Users\hasan.ismayilov\projects\other\ElectronJS\firstTry\node_modules\python-bridge\index.js:44:32)
at Object.onceWrapper (node:events:628:26)
at ChildProcess.emit (node:events:513:28)
at emit (node:internal/child_process:939:14)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
Venv and main.js are in same directory
I got this message at XCode after deleting some system files.
(lldb) script
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'run_python_interpreter' is not defined
P.S. Had to reinstall XCode, but I've got same message at debugger after reinstalling IDE
Terminal output
$ lldb
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 52, in <module>
import weakref
File "/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref
You have a local installation of python on your computer (in /usr/local/Cellar). There's a problem when you have two different pythons on your system; lldb links against /System/Library/Frameworks/Python.framework but that python somehow ends up using the python libraries from your installed copy instead. I saw someone work around this once but I forget if it was by putting their local python last in $PATH or if they un-set their $PYTHONPATH before starting lldb.
I recently set up Cuckoo environment on Arch Linux host with WXPSP3 guest.
When I try to upload file for analysis using submit.py I get the following error:
Traceback (most recent call last):
File "./utils/submit.py", line 23, in <module>
from lib.cuckoo.common.utils import to_unicode
File "/opt/cuckoo/utils/../lib/cuckoo/common/utils.py", line 11, in <module>
import xmlrpclib
ImportError: No module named 'xmlrpclib'
I run out of ideas. Could you help?
J
It works if I run python via python2.7 command so:
# python2.7 ./utils/submit.py <filepath>
I have a Python program originally built on and for Linux, which I'm now trying to port over to Windows. I am running the program in a virtual environment which contains all of the dependencies (my program is installed as a wheel with pip install --find-links wheels my_module). The program is launched with
(venv) C:\>venv\Scripts\python.exe -m base_module.Launcher arg1 arg2
The base_module loads my module as interpreted by the arguments provided, and his relevant code is:
from multiprocessing.managers import SyncManager
import OtherCustomClass
class BaseModule(object):
def __init__(self, arg1, arg2):
self.manager = SyncManager()
self.manager.start(ignore_interrupt)
def main(argv=None):
ret = -1
try:
basmod = BaseModule(argv[0], argv[1])
ret = basmod.run()
except Exception, err:
print("error: " + str(err))
print(traceback.format_exc())
return ret
if __name__ == "__main__":
exitCode = main(sys.argv[1:])
sys.exit(exitCode)
This has worked fine in Linux, but on Windows I get the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\Lib\multiprocessing\forking.py", line 380, in main
prepare(preparation_data)
File "C:\Python27\Lib\multiprocessing\forking.py", line 505, in prepare
'__parents_main__', file, path_name, etc
File "build/bdist.linux-x86_64/egg/base_module/BaseModule.py", line 2, in <module>
ImportError: No module named OtherCustomClass
exception in main:
Traceback (most recent call last):
File "build/bdist.linux-x86_64/egg/base_module/BaseModule.py", line 12, in main
File "build/bdist.linux-x86_64/egg/base_module/BaseModule.py", line 7, in __init__
File "C:\Python27\Lib\multiprocessing\managers.py", line 528, in start
self._address = reader.recv()
EOFError
The latter EOFError is caused by the unexpected early termination from the forking in SyncManager, where the true error is being unable to import OtherCustomClass. I have confirmed that OtherCustomClass exists in the base_module's folder within venv/lib/site-packages, and this error isn't happening when I launch the module first as Python would never reach the instructions in main() or init if the script wouldn't compile.
I've done some research, and I know this problem has hit other people (often using third party libraries, who fixed the issue without posting the solution). It seems to trace back to Windows' lack of a fork(), and python's handling of multiprocessing on Windows - see also http://docs.python.org/library/multiprocessing.html#windows. But I'm at a loss as to how to fix this.
This is the latest Python 2.7 branch (2.7.8), running on Windows 7 x64.
You can work around this by using an absolute import for OtherCustomClass:
from base_module import OtherCustomClass
I'm not exactly sure why, but it seems that when multiprocessing spawns a new process and imports your __main__, it's not able to handle the implicit relative import you're using with OtherCustomClass. If you explicitly import it from base_module, it works fine. My guess is that the spawned child process is not recognized as being part of the base_module package, so the implicit import fails, but that's just a guess.
Note that you shouldn't be using implicit relative imports anyway (they're altogether removed from Python 3), so switching to an absolute import isn't a bad thing.
Also of note, that doing an explicit relative import works on Python 3.4:
from . import OtherCustomClass
But it fails on Python 2.7:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\python27\lib\multiprocessing\forking.py", line 380, in main
prepare(preparation_data)
File "C:\python27\lib\multiprocessing\forking.py", line 495, in prepare
'__parents_main__', file, path_name, etc
File "C:\Users\oreild1\Desktop\base_module\Launcher.py", line 5, in <module>
from . import OtherCustomClass
ValueError: Attempted relative import in non-package
error:
Traceback (most recent call last):
File "C:\Users\oreild1\Desktop\base_module\Launcher.py", line 18, in main
basmod = BaseModule(argv[0], argv[1])
File "C:\Users\oreild1\Desktop\base_module\Launcher.py", line 10, in __init__
self.manager.start()
File "C:\python27\lib\multiprocessing\managers.py", line 528, in start
self._address = reader.recv()
EOFError
I use pattern.db module from pattern-2.5 in python to make a database, but when i run it, there is a message:
Traceback (most recent call last):
File "cobadb.py", line 25, in <module>
db = Database('my_stuff')
File "/usr/local/lib/python2.7/dist-packages/pattern/db/__init__.py", line 381, in __init__
_import_db(type)
File "/usr/local/lib/python2.7/dist-packages/pattern/db/__init__.py", line 54, in _import_db
import pysqlite2.dbapi2 as sqlite
ImportError: No module named pysqlite2.dbapi2
As is quite clear from the message, you need to install pysqlite2.