ImportError: cannot import name sandbox - google-app-engine-python

Over the past couple days, this has started cropping up whenever I run dev_appserver.py:
from google.appengine.tools.devappserver2.python import sandbox
ImportError: cannot import name sandbox
Since I was primarily coming across this in the setup of a new environment, I figured it must be a mistake of mine during setup. After enough head-scratching over the past 3 hours, I figured it couldn't be in the new setup, so I loaded up dev_appserver.py in a known-to-be-working environment.
Yet again:
from google.appengine.tools.devappserver2.python import sandbox
ImportError: cannot import name sandbox
None of my app code had been changed, so it had to be something else.

It turned out the SDK had changed.
I had a file named appengine_config.py that (specifically for the development server) whitelisted a couple of C modules.
from google.appengine.tools.devappserver2.python import sandbox
sandbox._WHITE_LIST_C_MODULES += ['_ssl', '_socket']
When I disabled these lines, this issue was replaced with another (the one that was the reason those lines were there to mitigate):
File "[...]/devappserver2/python/runtime/sandbox.py", line 1091, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named _socket
Notice the runtime piece in the filepath? Apparently the location of the sandbox module had changed. So I added .runtime to the import path:
from google.appengine.tools.devappserver2.python.runtime import sandbox
Then, after re-enabling those lines, everything was working again! ✅ Mission accomplished.
🎉

Related

How to import Project in Cube IDE 32 properly

enter image description here I need Help, I work on one project and yesterday i have accident and i damage my PC,I did Project backup and Now i try to import Projrct on my lap top, and i folow instructions but i folow some unexpected errors also, is saying that hal drivers is missing, i give propher path address to all folders but still not fixed, old project was worked fine on Win10 english FW1,5,1 i try to import in win 11 German, i download and add FW 1,5,1 but error still exist.
i try older backup version and still same messige. there is no missing files. just some incompatabiliity.

VSCode - Angular Material - No action to quickly import modules

In all the Angular projects using Material I have worked on in the past, VS Code can never find the name of the module I try to import.
If I try to add, for example, the MatButtonModule to the list of import, VS Code says Cannot find name 'MatButtonModule' and the quick action context doesn't propose to import it.
Up until now, I always had to write the import line manually.
I recently noticed I have the same issue with all their harnesses from the testing cdk.
The baseURL in my tsconfig file is /src and VSCode usually has no issue with any other import. It also work for material components.

Jython - import module does not work when run from Eclipse

I have a script 'localfunc.py' with different functions, and a main script 'doIt.py' with the following import code:
import localfunc
localfunc.aMethodToExecute()
I'm new to Python/Jython, but i think this is correct, right?
My problem is that when executed in Eclipse onto my local websphere server (right clic on script->Run as -> execute as administrative script) i get the following error message:
ImportError: no module named localfunc.
I'm using WAS 8.5.2 and Jython version is 2.1 for information.
Somebody has an idea why it's not working with Eclipse?
Quite easy finally to solve this problem. In your running configuration, update the setting in 'Arguments' > working directory by selecting 'other' and your main script directory.
For example if your working directory looks like:
src/scripts/
start.py
lib/
localfunc.py
Select 'src/scripts/'
It works now.

Setup of PyDev and Eclipse for Blender Add-Ons

I followed the instructions in this ebook Programming Add-Ons for Blender 2.5 to setup a development environment.
Currently I try to debug an installed add-on called Bloop although it seems to work, eclipse still shows many error messages like:
class Mapping(object):
def __init__(self, joint=None, id=None, bone=None, other=None):
...
self.bone_matrix = bpy.bloop.armature.matrix_world.inverted() * self.bone.bone.matrix_local.inverted()
^^^^
ErrorMsg: Undefined variable from import: bloop
The external libraries are configured as follows:
Blenders version is 2.67, the add-on was developed for 2.59. I have absolutely no experience with Python in blender.
Another type of errors is:
Unresolved import: MappingSet bloop.py
from .mapping_set import MappingSet
Where MappingSet is in the same folder as bloop.py which tries to import.
The projects structure is as follows (I don't have a source folder since I want to edit in place)
What am I doing wrong?
A workaround to suppress at least the error messages is using ##UnresolvedImport and ##UndefinedVariable at the end of those lines.
I setup debug differently but still based on the lux-render tutorial.
First, create the a .py file, lets call it debug.py, which will contain a function which we will call later to setup debugging. Put this file in the same folder as the main __init__.py of your module. As per the lux-renderer tutorial, add the following code, updating PYDEV_SOURCE_DIR.
import sys
def startdebug():
try:
# set the PYDEV_SOURCE_DIR correctly before using the debugger
PYDEV_SOURCE_DIR = 'C:\Program Files\eclipse\plugins\org.python.pydev.debug_2.5.0.2012040618\pysrc'
# test if PYDEV_SOURCE_DIR already in sys.path, otherwise append it
if sys.path.count(PYDEV_SOURCE_DIR) < 1:
sys.path.append(PYDEV_SOURCE_DIR)
# import pydevd module
import pydevd
# set debugging enabled
pydevd.settrace(None, True, True, 5678, False, False)
except:
pass
When setting the PYDEV_SOURCE_DIR ensure you point it to the org.python.pydev.debug_xxxxx. There is another folder similiar to this. To ensure you have the correct folder it will contain a /pysrc folder.
Now in your main __init__.py, this must come before any other import statements to work correctly. Add the following directly under the bl_info section, as strangely blender parses this itself.
DEBUGGING = True
if(DEBUGGING):
import debug
debug.startdebug()
Having it here will avoids adding per file traces like the lux-render tutorial.
Add some breakpoint to the version in the add-ons folder,
Switch to the debug perspective,
Start Eclipses debug server,
Start blender
Run the script and it will hit the breakpoint.
The common problems I find people encounter:
pointing the path to the wrong pydev debug folder, ensure that there is a /pysrc folder
When Pydev updates, update the PYDEV_SOURCE_DIR as the debug_xxxxx will have change
not having eclipse server running,
setting breakpoints on a local copy of the files instead of the version in the blender add-on directory
saving the script does not mean that blender will reload it, use imp, disable/renable the add-on or restart Blender.
There are good instructions for setting up blender and eclipse for debugging.
http://wiki.blender.org/index.php/User:Z0r/PyDevAndProfiling
While this is for blenders game engine, much of it applies to regular blender. Hope this help!
EDIT: I deleted it because I felt that this doesn't answer your question. But here it is since you insisted.

Suppress warnings in PyDev

I use the following at the beginning of all modules in my Python project:
import setup_loggers
setup_loggers is a module that does exactly that. The import statement makes sure that no matter which module is loaded first, the loggers are setup and ready.
However, as I don't use setup_loggers module later in the file, I receive a PyDev warning (a small yellow marker). I get this warning for all my modules, thus it blocks me from seeing other warnings in the PyDev Package Explorer.
Is there a way to suppress the warning for a specific line (the import line above) in PyDev?Any other ideas on how to overcome this annoyance?
In PyDev, whenever there's an error in a line, you can press Ctrl+1 and it'll show an option to ignore that warning in that line (in this case, it'll add a comment: ##UnusedImport -- which you could add manually -- in that line and that error/warning will be ignored).
Now, on to a better strategy for you (so that you don't have to import that module everywhere): in Python, when you do the import of a package, the parents will be imported before.
I.e.:
/my_project
/my_project/__init__.py
/my_project/submodule.py
/my_project/package
/my_project/package/__init__.py
When you import the my_project.submodule or my_project.package, it'll first have to import (and execute) the code in /my_project/__init__.py
So, a better strategy for you would be only adding that import to the /my_project/__init__.py (and whenever any submodule is imported, the loggers would be already setup).
It just wouldn't work if you have a collection of files that are scattered in the PYTHONPATH root and on the file you execute as your __main__ (as it won't import that file, it'll just get its contents and execute it -- but whenever that file imports anything from /my_project, things would be setup).