I have a pydev project going in aptana studio 3.
In the image below, you can see my project structure and the fact that my nosetests are all passing.
If I click on a file scheduled.py that has a breakpoint in it, and hit debug as > python run it fails to be able to import my modules.
pydev debugger: starting
Traceback (most recent call last):
File "C:\Users\mapserv\AppData\Local\Aptana Studio 3\plugins\org.python.pydev_2.7.0.2012110722\pysrc\pydevd.py", line 1397, in <module>
debugger.run(setup['file'], None, None)
File "C:\Users\mapserv\AppData\Local\Aptana Studio 3\plugins\org.python.pydev_2.7.0.2012110722\pysrc\pydevd.py", line 1090, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "C:\Users\mapserv\Desktop\Projects\Aptana\AutomatedCaching\agrc\caching\scheduled.py", line 1, in <module>
from agrc.caching.commands import cache
ImportError: No module named agrc.caching.commands
I've noticed that aptana has the notion of packages/modules. Is there something wrong with my project structure that is causing this? Should my folders be packages? Do I need to setup more things with my interpreter which looks like?
Edited
If I try to run scheduled.py from the command line it has the same problem. How is nose running my tests and making everything happy yet it doesn't work outside of that?
Well the answer was to update your PYTHONPATH. On windows, put the path to the AutomatedCaching folder inside the automated_caching.pth file.
eg: C:\Projects\AutomatedCaching
Then move the file into your site packages folder. For arcgis users it will be something like
C:\Python27\ArcGISx6410.1\Lib\site-packages
or
C:\Python27\ArcGIS10.1\Lib\site-packages
depending if you installed server and desktop. I'm thinking the last install wins the PATH war? I installed server then desktop and it uses the second in the path without the x64.
running
import sys
for i in sys.path:
print i
should verify that your location has been added.
Now the fact that arcgis for server and desktop install two different pythons into c:\python27 is a whole different story.
Now aptana shows my package explorer like it is a package
Did you try putting it in your "PyDev - PYTHONPATH" project properties? Project -> Properties -> PyDev - PYTHONPATH -> Source Folders(tab) -> Add source folder.
Then you don't have to mess with your system PYTHONPATH.
It worked for me.
Tried to post an image but I guess I don't have enough reputation points.
Related
I recently started to working on WSL Ubuntu-20.04. There is no problem on running the server. But when I tried to connect the Django Console of Pycharm, I get the error below:
Traceback (most recent call last):
File "<input>", line 7, in <module>
ModuleNotFoundError: No module named 'django_manage_shell'
I checked the consoles interpreter and starting script, tried to add project path, my virtualenv path but nothing worked.
My Django Console Options
This is starting script:
import sys; print('Python %s on %s' % (sys.version, sys.platform))
import django; print('Django %s' % django.get_version())
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
if 'setup' in dir(django): django.setup()
import django_manage_shell; django_manage_shell.run(PROJECT_ROOT)
I had no issues like this when I working on Ubuntu nor Windows. This issue happened with WSL.
So I'm waiting for your helps and thanks a lot for your time.
I'm not on WSL but this question came up when I was searching for a solution and Hassaan AlAnsary's answer helped me.
On Linux, running PyCharm 2022.2.1, with Python in Docker, I got this error and solved it by modifying the starting script in Settings -> Build, Execution, Deployment -> Console -> Django Console.
I took the line:
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
and I added the location of the helper in the Docker container:
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS, "/opt/.pycharm_helpers/pycharm"])
and this fixed the problem.
So, I have a terrible workaround for this, and I will leave it here for fellow travelers passing through this lonely part of StackOverflow. But I hope someone else can do better.
The django_manage_shell module is coming from PyCharm's helpers, and isn't part of the normal Django distribution. When running under WSL, these helpers are not accessible to the python interpreter, and you get the above error.
The best solution I was able to arrive at was to make the code in that helper module accessible in the startup script. Fortunately, you can get at this module (and the fix_getpass module it relies on) with only mild difficulty. The code for each can be found in these spots (depending on your PyCharm installation):
C:\Program Files\JetBrains\PyCharm 2021.2\plugins\python\helpers\pycharm\django_manage_shell.py
C:\Program Files\JetBrains\PyCharm 2021.2\plugins\python\helpers\pycharm\fix_getpass.py
I took the code I found in those modules, and pasted it into the Django Console startup script in PyCharm. I had to reorganize things a bit, and change the call django_manage_shell.run() to invoke the copied-over code instead.
I cannot stress how brittle and gross this approach is, but I haven't found an alternative. If I figure out a better approach, or if JetBrains fixes this on their own, I'll come back and update this answer.
EDIT: Slight improvement to my original solution, which involved a rogue python module on the WSL side. This avoids polluting your project, and constrains the hack to just the PyCharm side of things.
as #Nacho said, it is because PyCharm can't reach the helpers folder on Windows Host machine from within WSL.
You can add the path to the PyCharm helpers folder to your path mapping.
consequently, all the helper files will be reachable by pycharm
One way to do that is to:
Open Setting -> Build, Execution, Deployment -> Django Console
add new Path Mapping
local path
C:/Program Files/JetBrains/PyCharm 2021.3.3/plugins/python/helpers/pycharm
remote path
/mnt/c/Program Files/JetBrains/PyCharm 2021.3.3/plugins/python/helpers/pycharm
Close the console and open it again
modify the path above according to your PyCharm version and WSL setup
now PyCharm will be able to locate django_manage_shell and any other
I just finished creating a python program in 2.7 and I converted it to a .exe with py2exe.
Everything works fine when I run the converted executable file in the folder I placed it in with all of the images in it. After converting the python program to .exe, I proceeded to creating a setup file for it. I added all of the files associated with my project including tkinter in the setup file. I added pretty much everything that let me run the executable.
Once I finished creating the setup file, I opened it. I went through everything and finished installing it on my system and created a shortcut on my Desktop. When I tried to open it, it would not work. Instead of running the program, it tells me to open a log file in its folder in the Program Files. When I open the log file, I noticed an error. How do I fix this?
Error:
Traceback (most recent call last):
File "gui.py", line 10, in <module>
File "Tkinter.pyc", line 1764, in __init__
_tkinter.TclError: Can't find a usable init.tcl in the following directories:
{C:/Program Files (x86)/lib/tcl8.5} {C:/Program Files (x86)/lib/tcl8.5} C:/lib/tcl8.5 {C:/Program Files (x86)/library} C:/library C:/tcl8.5.15/library C:/tcl8.5.15/library
This probably means that Tcl wasn't installed properly.
I found a bug on the virutalenv site which suggested the following https://github.com/pypa/virtualenv/issues/93
I imagine that you are encountering the same issue just without virtualenv
the following set the correct paths which can then be included in the application please find the right path to TCL and TK for your python version
set "TCL_LIBRARY=C:\Python27\tcl\tcl8.5"
set "TK_LIBRARY=C:\Python27\tcl\tk8.5"
restart your cmd or shell
I believe that the TCL location have changed from there default ones.
When I try to run any of my app engine projects by python GoogleAppEngineLauncher
I got the error log as follows:
Does anyone have any ideas of what's going on?
I tried remove the SDK and reinstall it. Nothing happens. Still got the same error.
Everything is working fine and I don't think I made any changes before this happens.
The only thing that I can think of is that I install bigquery command line tool before this happens. But I don't think this should be the reason of this.
bad runtime process port ['']
Traceback (most recent call last):
File
"/Users/txzhang/Documents/App/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/_python_runtime.py",
line 197, in
_run_file(file, globals()) File "/Users/txzhang/Documents/App/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/_python_runtime.py",
line 193, in _run_file
execfile(script_path, globals_) File "/Users/txzhang/Documents/App/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/runtime.py",
line 175, in
main() File "/Users/txzhang/Documents/App/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/runtime.py",
line 153, in main
sandbox.enable_sandbox(config) File "/Users/txzhang/Documents/App/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py",
line 159, in enable_sandbox
import('%s.threading' % dist27.name) File "/Users/txzhang/Documents/App/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py",
line 903, in load_module
raise ImportError('No module named %s' % fullname) ImportError: No module named google.appengine.dist27.threading
The most probable reason is having another python package that is coming from google. Run
python in verbose mode with python -vvvvv and try following command import google.
If the above import is successful make sure its coming from /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google which is the path of python google appengine libraries on my system (OSX, fresh install of google appengine sdk).
If that is not the case (but the import is successful) then its most likely other existing google libraries which are creating issue and the path of the same would be visible on python prompt after the successful import google command like following:
>>> import google
import google # loaded from Zip
/Library/Python/2.7/site-packages/protobuf-2.4.1-py2.7.egg/google/init.pyc
In this case my google protobuf package was the culprit.
Solution:
Use virtualenv: If you haven't used python virtualenv before, may be this is the best time to use it. (a) Make sure that your PYTHONPATH variable is not set to include anything that has a google package! Unset it running unset PYTHONPATH (in your bash prompt) unless you are very sure what you have there. (b) Create a new python virtualenv, activate it and try to run google appengine commands in it:
virtualenv --no-site-packages /tmp/googleapps
source /tmp/googleapps/bin/activate
dev_appserver.py path_to_google_app
Remove conflicting packages from path: Move conflicting packages a new virtualenv. This is likely to break other stuff so not recommended.
I had hit the same issue today. This being the top result on google but lacked any answers, I add this after fixing same issue on my system. There may be other possible reasons which thankfully I haven't come across.
Good luck!
A recent upgrade of the development SDK started causing this problem for me. After much turmoil, I found that the problem was that the SDK was in a sub-directory of my project code. When I ran the SDK from a different (parent) directory the error went away.
I'm running Eclipse Juno with Pydev. I compiled an egg package that imports a C library using ctypes. It works fine from the terminal, but when run from inside Eclipse I get
/usr/local/lib/python2.7/dist-packages/PhreeqPy-0.1.0-py2.7.egg/phreeqpy/iphreeqc
Traceback (most recent call last):
File "/src/pywork/fddarcy/src/fddarcy.py", line 75, in <module>
sys.exit(main())
File "/src/pywork/fddarcy/src/fddarcy.py", line 35, in main
freak =phreeqc_mod.IPhreeqc()
File "/usr/local/lib/python2.7/dist-packages/PhreeqPy-0.1.0-py2.7.egg/phreeqpy/iphreeqc/phreeqc_dll.py", line 28, in __init__
self.phreeqc = ctypes.cdll.LoadLibrary(dll_path)
File "/usr/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libimf.so: cannot open shared object file: No such file or directory
After reloading all libraries in Pydev Eclipse is not even giving errors when importing the module, but it doesn't load the module. Just to be extra clear, everything works fine from the terminal.
EDIT: I think that the problem is in the way Eclipse is calling python. Is it any different from the way python is called from the terminal?
Cheers
If you haven't already, you may need to add it to the PYTHONPATH within Eclipse.
Window -> Preferences -> PyDev -> Interpreter - Python
Add your python.exe or run autoconfig and then add the libraries you need.
Eclipse is seeing the ctypes module, it's just that ctypes can't find the DLL.
The reason for this is that eclipse doesn't necessarily use your system's environment variables. To remedy this problem, you need to set the LD_LIBRARY_PATH within Eclipse.
Step 1. Figure out where "libimf.so" is on your system. On Linux, you can use:
locate libimf.so
in a terminal. That should give you the directory. For example, say the file is at "/home/sweetlibraries/libimf.so" .
Step 2. Set LD_LIBRARY_PATH in Eclipse*:
Right click on the python file that you're running that gives this error.
Click "properties"
Click "Run/Debug Settings"
You should see some configuration for the file. For me, it's "project_name python_file_name.py". Select it.
Click "Environment"
Click "New"
Set Name to "LD_LIBRARY_PATH"
Set Value to wherever you found libimf.so, e.g. "/home/sweetlibraries/"
Click "OK" to get out of all those menus.
Now when you run it, it should work. If not, make sure you use the right "run configuration". Click the little down arrow next to the big, green "run" arrow. and select the configuration name (e.g. "project_name python_file_name.py").
*I'm using LiClipse, but I think the menu structure should be identical.
I made a single slideshow.py file to display some photo correction with Tkinter widget, it runs perfectly on my windows & linux.
To made it run on windows without python and tcl installed, I use py2exe to compile it into a win32 executable, setup.py is simple:
from distutils.core import setup
import py2exe
setup(windows=["slideshow.py"])
Then I run "python setup.py py2exe", it generate a "dist" folder in c:\Users\d2xia\ccm_wa\utils\tfps\, and "tcl", "library.zip", "slideshow.exe" and so on under it.
When I run slideshow.exe it errors:
Traceback (most recent call last):
File "slideshow.py", line 45, in <module>
File "Tkinter.pyc", line 1685, in __init__
_tkinter.TclError: Can't find a usable init.tcl in the following directories:
C:/Users/d2xia/ccm_wa/utils/tfps/lib/tcl8.5 C:/Users/d2xia/ccm_wa/utils/tfps/lib/tcl8.5 C:/Users/d2xia/ccm_wa/utils/lib/tcl8.5 C:/Users/d2xia/ccm_wa/utils/tfps/library C:/Users/d2xia/ccm_wa/utils/library C:/Users/d2xia/ccm_wa/utils/tcl8.5.11/library C:/Users/d2xia/ccm_wa/tcl8.5.11/library
tcl8.5 and tk8.5 actually resides under the "tcl" folder, but it seems the exe generated by py2exe still looks under "lib" or "library", it seems it doesn't set the correct TCL_LIBRARY and TK_LIBRARY.
Even if I rename the "tcl" to "lib", it still get the same errors.
set TCL_LIBRARY=c:\Users\d2xia\ccm_wa\utils\tfps\dist\tcl\tcl8.5\
set TK_LIBRARY=c:\Users\d2xia\ccm_wa\utils\tfps\dist\tcl\tk8.5\
then slideshow.exe generate some new errors:
c:/Users/d2xia/ccm_wa/utils/tfps/dist/tcl/tcl8.5/init.tcl: version conflict for package "Tcl": have 8.5.11, need exactly 8.5.2
version conflict for package "Tcl": have 8.5.11, need exactly 8.5.2
while executing
"package require -exact Tcl 8.5.2"
(file "c:/Users/d2xia/ccm_wa/utils/tfps/dist/tcl/tcl8.5/init.tcl" line 20)
invoked from within
"source c:/Users/d2xia/ccm_wa/utils/tfps/dist/tcl/tcl8.5/init.tcl"
("uplevel" body line 1)
invoked from within
"uplevel #0 [list source $tclfile]"
I have Tcl 8.5.11 in C:\apps\git\lib\tcl8.5
and Tcl 8.5.2 in C:\Python27\tcl\tcl8.5
It seems when I run with python, it looks for tcl in python installation path, but py2exe looks a different copy in the git installation path.
So then questions become:
1. How to "assign" a correct tcl8.5 copy to py2exe when create the dist?
2. How to let the generated executable aware of the tcl path in the dist? "tcl" instead of "lib" or "library"
Tcl version 8.5.11 & 8.5.2 conflicts solved by manually replace tcl8.5, tk8.5, tcl85.dll and tk85.dll with the ones from python installation path, I believe it can also be solved by change the path environment variable.
But I still have to manually set the TCL_LIBRARY and TK_LIBRARY, I made a windows batch wrapper test.bat:
set TCL_LIBRARY=.\tcl\tcl8.5\
set TK_LIBRARY=.\tcl\tk8.5\
slideshow.exe %1
This works, any better ideas?
A correct Tcl and Tk installation will have the right value of those environment variables baked into it during build time; they only really exist to permit testing prior to installation (very useful for the developers of Tcl/Tk, best avoided for everyone else). If they're not connected up properly, or are finding the wrong version of the script libraries, there's a serious problem with your installation. (Note that this does mean that you should not normally move things around after installation, but that's not too much of a problem for most people.)
The usual advice in this sort of situation is to wipe the Tcl and Tk installations and start again, making sure that the correct installation location is specified to configure via the --prefix option. I have no idea how the addition of Python into the mix affects things.