I am trying to debug my application with Pydev 1.5
I have done almost everything that's mentioned in the docs to start the debugger.
I get this error when I try to start the debugging:
pydev debugger: warning: psyco not available for speedups (the debugger will still work correctly, but a bit slower)
pydev debugger: starting
Traceback (most recent call last):
File "C:\Documents and Settings\mkallat\Desktop\eclipse\plugins\org.python.pydev.debug_1.5.0.1251989166\pysrc\pydevd.py", line 953, in <module>
debugger.run(setup['file'], None, None)
File "C:\Documents and Settings\mkallat\Desktop\eclipse\plugins\org.python.pydev.debug_1.5.0.1251989166\pysrc\pydevd.py", line 780, in run
execfile(file, globals, locals) #execute the script
File "Z:\dev\hfholidays\urls.py", line 1, in <module>
from django.conf.urls.defaults import *
ImportError: No module named django.conf.urls.defaults
Please suggest me what's the best solution to this. Or am I missing something?
Thanks in advance.
You are missing django - pydev cannot find the django modules
You need to have all the python modules you need accessible to python this is usually done by having the environment variable PYTHONPATH include the directory of the module.
In pydev go to project->Properties->Pydev-PYTHONPATH choose the External libraries tab. You need to add the django package to your path.
Alternatively the normal Djano install should have put django into python's site-packages and so should be available on PYTHONPATH
Related
I am trying to concatenate some pdf files from the command line on mac.
After reading online I found there is a python script for this located here:
/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py
After resetting my python to be the system's 2.7 python (sudo port select --set python python27), I get this error when trying to run the above script:
Traceback (most recent call last):
File "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py", line 23, in <module>
from CoreFoundation import *
ImportError: No module named CoreFoundation
So apparently python is not able to import something called CoreFoundation. Looking, I find said CoreFoundation.py at this place on my file system:
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/Carbon/CoreFoundation.py
And, indeed, inspecting the sys.path variable seems to indicate that the above directory is somehow overlooked:
$ python
>>> import.sys
>>> sys.path
['', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages']
(Pardon the long unbroken line. The point is, things like
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages'
are found in sys.path, but the arefore-mentioned
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/Carbon'
is not.) So I try to manually add to PYTHONPATH (which was previously empty):
PYTHONPATH="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/Carbon"
...but even after doing this, I get the same ImportError: No module named CoreFoundation error.
What should I do?
So I've installed scons via Anaconda's conda install scons under Windows 10 (Python 3.6) and could not execute it via the command line so I've added C:\Users\D\Anaconda3\envs\py36\Scripts\ to my Path (even tough C:\Users\Dominik\Anaconda3 was already in there).
Now I can execute it in the Powershell, but I get an error, because it is unable find engine files:
scons
SCons import failed. Unable to find engine files in:
C:\Users\D\Anaconda3\envs\py36\Scripts\..\engine
C:\Users\D\Anaconda3\envs\py36\Scripts\scons-local-3.0.1
C:\Users\D\Anaconda3\envs\py36\Scripts\scons-local
C:\Users\D\Anaconda3\scons-3.0.1
C:\Users\D\Anaconda3\Lib\site-packages\scons-3.0.1
C:\Users\D\Anaconda3\scons
C:\Users\D\Anaconda3\Lib\site-packages\scons
Traceback (most recent call last):
File "C:\Users\D\Anaconda3\envs\py36\Scripts\scons.py", line 192, in <module>
import SCons.Script
ImportError: No module named 'SCons'
Does someone know how to further investigate/fix this problem?
I found it thanks to nekomatic.
If you use the anaconda prompt (with the correct environment activated or in my case the correct shortcut leading to anaconda prompt in that environment), scons runs just fine.
See this link explaining how anaconda uses the path on windows and whats the advantage of using the anaconda prompt (mainly it dynamically manages PATH correctly for that session only with full knowledge of conda environments).
I have generated a SWIG python binding of a C++ library. I would like for others to be able to script it using python directly, but I would also like to embed python in my application so users can setup python scripts to modify variables at runtime. When I run python or python_d I can import my release and debug versions of my library with no issues and then use them. However, when I try and embed them I can run the following code with no issues in release mode, but in debug mode I get the error below.
Embedded code:
Py_SetProgramName("AnimatLab");
Py_Initialize();
PyRun_SimpleString("import os\n"
"os.chdir(\"C:/Projects/AnimatLabSDK/AnimatLabPublicSource/bin\")\n"
"import AnimatSimPy\n");
Py_Finalize();
Error:
C:\Projects\AnimatLabSDK\AnimatLabPublicSource\bin
Traceback (most recent call last):
File "<string>", line 4, in <module>
ImportError: No module named AnimatSimPy
I know the _AnimatSimPy_d.pyd works in debug mode because I can import and use it when I run python_d, but for some reason it will not run when embedded. Does anyone have any ideas on why this is failing? I am linking the debug version to python27_d.dll on a 64 bit windows 7 machine.
I figured this out. I am not sure why, but in debug mode it required me to append to my paths to add the directory where the dll was and not just set the working directory. For release mode it worked without this. So if I run the code below it works in both debug and release mode from the embedded code.
Py_SetProgramName("AnimatLab");
Py_Initialize();
PyRun_SimpleString("import os\n"
"import sys\n"
"sys.path.append(\"C:/Projects/AnimatLabSDK/AnimatLabPublicSource/bin\")\n"
"os.chdir(\"C:/Projects/AnimatLabSDK/AnimatLabPublicSource/bin\")\n"
"import AnimatSimPy\n");
Py_Finalize();
I am new to python but have been using both IDLE and EricIDE for a few weeks without any major problems.
I was editing a program I had written that called random.randint() function and it wouldn't work.
Previously, this program had been working and I had not changed that call out.
I then loaded another program that uses the same function that had been working and it would not run either.
I tried to load the program in IDLE but IDLE wouldn't load. After trying several reboots and reloads EricIDE wouldn't load either. I noticed a black window popping up and disappearing quickly when I try to launch either IDE from my previously working desktop shortcuts.
Searching for help led me to run python shell from the windows command line by going to C:\python33\ and typing "python" to run python shell, I get:
File "C:\python33\lib\sre_constants.py", line 18, in (module)
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
I am using Windows 8 (new to it as well and still trying to figure it out).
At this point I'm assuming my problem is with my python installation since the python shell won't work. I have uninstalled and reinstalled Python 3.3.1 but the problem persists. I also deleted the .idlerc folder from my Users directory as suggested in another thread that was similar to my problem but that doesn't seem to have helped either.
Thank you for any help you can provide.
response to eryksun:
C:\Python33>python.exe -c "import sys; print(sys.path)"
Traceback (most recent call last):
File "C:\Python33\lib\site.py", line 70, in <module>
import re
File "C:\Python33\lib\re.py", line 122, in <module>
import sre_compile
File "C:\Python33\lib\sre_compile.py", line 14, in <module>
import sre_parse
File "C:\Python33\lib\sre_parse.py", line 17, in <module>
from sre_constants import *
File "C:\Python33\lib\sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
C:\Python33>python.exe -S -c "import sys; print(sys.path)"
['', 'C:\\Python33\\python33.zip', 'C:\\Python33\\DLLs',
'C:\\Python33\\lib', 'C:\\Python33']
Follow up to to eryksun:
C:\Python33>python.exe -S -c "import _imp; _sre = _imp.init_builtin('_sre');
print(_sre.MAXREPEAT)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'MAXREPEAT'
I suggest you uninstall. Completely remove C:\Python33 and also C:\Windows\System32\python33.dll. _sre is built in to the latter DLL. MAXREPEAT is set by its initialization functionPyInit__sre (Modules/_sre.c). Clearly, something is wrong there.
When you download the 3.3.1 installer, make sure you get the right binary for your platform, i.e. x86 for 32-bit Windows and X86-64 for 64-bit Windows.
I've looked around on SO, and the answers I have found to my problem haven't allowed me to solve it yet.
I want to use isolated virtualenv environments, but for one reason or another, virtualenv keeps loading global site packages, when in django's shell...
I tried to clean up PATH variables, until only c:\Python26\Scripts and c:\Python26 remain. I then create my environment.
virtualenv --distribute --no-site-packages myproject
I then activate the virtualenv. PATH is now (irrelevant vars scrapped):
PATH=E:\Development\django_projects\myproject\Scripts;C:\Panda3D-1.7.0\python;C:\Panda3D-1.7.0\bin;c:\python26\Scripts;
PYTHONPATH=C:\Panda3D-1.7.0\
So far, so good. I launch python...
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
Let's just try a module I'm sure is in my c:\python site-packages directory.
>>> import BeautifulSoup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named BeautifulSoup
Yay! No global site packages! On to the next one then. From the command prompt, I type:
django-admin.py
And it works! But wait... I haven't installed Django yet. How is this possible?
After this, it gets even weirder... I first add these to virtualenv's activate.bat script so that Django can find my settings.
set PYTHONPATH=E:\Development\django_projects\myproject\
set DJANGO_SETTINGS_MODULE=settings.development
Now I launch django-admin.py shell and
In [1]: import BeautifulSoup
In [2]: BeautifulSoup.__file__
Out[2]: 'C:\\Python26\\lib\\site-packages\\BeautifulSoup.pyc'
How is this even possible?
Flash of insight
While typing this, I suddenly get it. .py is a file extension coupled with my c:\python26\python.exe executable, instead of the virtualenv one!
python manage.py
Traceback (most recent call last):
File "manage.py", line 2, in <module>
from django.core.management import execute_manager
ImportError: No module named django.core.management
Heh. Anyone has any idea of how to couple the .py file extension to my virtualenv's python executable instead of the system defined python executable?
A little bit of extra .bat hackery can easily fix this. My standard additions to activate.bat are:
REM custom venv settings
set PYTHONPATH=%\VIRTUAL_ENV%;%\VIRTUAL_ENV%\conf;%\VIRTUAL_ENV%\apps
set DJANGO_SETTINGS_MODULE=settings
ftype Python.File=%VIRTUAL_ENV%\Scripts\python.exe %1 %*
and to deactivate.bat
REM restore ftype
ftype Python.File=C:\tools\Python27\python.exe %1 %*
You could make a .bat file and modify PATH and PYTHONPATH in there, and then run .py from that .bat file.
Something like this i think
set PATH=C:\Python26;
python myfile.py
Ofcourse, add anything else to your path that you want.
I had the same "Access denied" problems as Dan with m0nonoke's answer on my Windows 7 setup using cmd.exe.
But I found this work around using a replacement shell TCC/LE and a customised startup file...
Under working directory create subdirectory config. In this directory
create startup file for TCC/LE called tcstart.btm
#echo off
rem Override system python binding to handle virtualenvironments
set .py;.pyc=python.exe
Now create (copy) TCC/LE shortcut on desktop and rename it
appropriately. Open Properties for shortcut and add to Target
“C:\django\config\tcstart.btm”. You probably want to set Start in to
something useful, like C:\django
Solution found in this guide on installing Django and Windows.