Django can't find can't find packages in virtualenv - python

I'm trying to set up a virtualenv for local development using Google App Engine and django-nonrel. I'm only trying to run the test app provided by django-nonrel for now.
The first time I tried, I got python manage.py runserver to work, but as soon as I tried to fetch a page from localhost:8080, it errored out on me, saying it couldn't find the pdb module:
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2755, in _HandleRequest
self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2643, in _Dispatch
base_env_dict=env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 682, in Dispatch
base_env_dict=base_env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1717, in Dispatch
self._module_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1619, in ExecuteCGI
reset_modules = exec_py27_handler(config, handler_path, cgi_path, hook)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1425, in ExecutePy27Handler
import pdb
ImportError: No module named pdb
I tried copying modules from my main Python installation, and I also tried creating a new virtualenv which had access to site-packages. Both approaches worked up to a point - python manage.py runserver ended up not being able to find urllib.
On the other hand, python manage.py shell and then e.g. import pdb or import urrlib (or any other standard library, for that matter) work fine. What am I supposed to do?

The solution: don't use virtualenv at all, and put the libraries you're going to need (such as django) in your project directory. You're going to need that to deploy your app to GAE, anyway.

Related

Thonny IDE throws AssertionError on startup

I have faced error while opening the Thonny Ide.
ERROR: Internal error
Traceback (most recent call last):
File "C:\Program Files (x86)\Thonny\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Program Files (x86)\Thonny\lib\site-packages\thonny\running.py", line 356, in cmd_stop_restart
self.restart_backend(True)
File "C:\Program Files (x86)\Thonny\lib\site-packages\thonny\running.py", line 458, in restart_backend
self._proxy = backend_class(clean)
File "C:\Program Files (x86)\Thonny\lib\site-packages\thonny\running.py", line 1036, in __init__
CPythonProxy.__init__(self, executable)
File "C:\Program Files (x86)\Thonny\lib\site-packages\thonny\running.py", line 624, in __init__
self._start_new_process()
File "C:\Program Files (x86)\Thonny\lib\site-packages\thonny\running.py", line 764, in _start_new_process
debug("Starting the backend: %s %s", cmd_line, get_workbench().get_cwd())
File "C:\Program Files (x86)\Thonny\lib\site-packages\thonny\workbench.py", line 1252, in get_cwd
return normpath_with_actual_case(os.path.expanduser("~"))
File "C:\Program Files (x86)\Thonny\lib\site-packages\thonny\common.py", line 212, in normpath_with_actual_case
assert os.path.isabs(name)
AssertionError
OS: Windows 7 64-bit
Python: Python 3.7(94bit)
Thonny:3.1.2
Open %APPDATA%\Thonny\configuration.ini (or wherever your IDE config is)
Scroll down to [run] section and check parameter working_directory.
Make sure something meaningful is set there, e.g. C:\ should do the trick (no double backslahes, quotes, etc..).
I had the same issue. For some reason only word lib was there. Modifying this parameter to a proper filesystem path fixed it in my case.
Something has corrupted the current instance of your Thonny installation at the backend.
You will first need to completely uninstall Thonny and then remove any imprints of Thonny from your computer's registry.
Then reinstall Thonny and open Thonny IDE.
Hope this helps.
I also faced this issue, for me it was due to Antivirus, just disabling Auto Containment fixed the issue, Hope this helps.

PyCharm debugger fails with AttributeError

I cannot debug a Flask application in PyCharm. The application should run on port 5000: app.run(host="10.1.0.17", port=5000, debug=True). The console output is:
C:\Python\python.exe "C:\Program Files (x86)\JetBrains\PyCharm 145.597.11\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 10498 --file "D:/TGM/SMS/SMS/Back .v2/wsgi.py"
pydev debugger: process 4108 is connecting
Could not connect to 127.0.0.1: 10499
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 145.597.11\helpers\pydev\pydevd.py", line 1523, in <module>
debugger.connect(host, port)
File "C:\Program Files (x86)\JetBrains\PyCharm 145.597.11\helpers\pydev\pydevd.py", line 317, in connect
self.initialize_network(s)
File "C:\Program Files (x86)\JetBrains\PyCharm 145.597.11\helpers\pydev\pydevd.py", line 304, in initialize_network
self.writer = WriterThread(sock)
File "C:\Program Files (x86)\JetBrains\PyCharm 145.597.11\helpers\pydev\_pydevd_bundle\pydevd_comm.py", line 392, in __init__
self.cmdQueue = _queue.Queue()
AttributeError: module 'queue' has no attribute 'Queue'
Process finished with exit code -1
I am using Python 3.5.1. What could be wrong?
The pydev debugger uses the same Pythonpath as the project you are trying to debug.
If you have any modules or packages with names of standard modules or packages, the pydev debugger might load your module instead of the standard module.
You probably have a module called queue in your projects directories, which causes this issue, since the python standard library also includes a module with that name.
try renaming your module, or changing your PYTHONPATH
PyCharm has the option to not include the projects root/source roots in the PYTHONPATH in Run > Edit Configurations. This could fix your problem, although you might need to fix some import statements in your project, if any of your import statements relied on this setting.

App Engine Python won't start

I don't know what changed, but suddenly none of my Python App Engine projects will start on my PC. They start on my MacBook just fine, so there's something about the installation on my PC that's messed up. I've tried going back to 1.8.8, but that doesn't work. I've also tried using a fresh Python installation, but that didn't work. I've even tried using port 8080 (I usually use port 80, as I run the app launcher as admin).
This is what shows up in the error log when I click start on one of my projects:
2014-02-05 10:42:24 Running command: "['c:\\users\\jonathan\\appdata\\local\\enthought\\canopy\\user\\scripts\\pythonw.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=80', '--admin_port=8000', 'C:\\Users\\jonathan\\My Repositories\\my-project']"
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 197, in <module>
_run_file(__file__, globals())
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 193, in _run_file
execfile(script_path, globals_)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 32, in <module>
from google.appengine.tools.devappserver2.admin import admin_server
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\admin\admin_server.py", line 29, in <module>
from google.appengine.tools.devappserver2.admin import console
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\admin\console.py", line 22, in <module>
from google.appengine.tools.devappserver2 import module
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\module.py", line 69, in <module>
from google.appengine.tools.devappserver2 import wsgi_server
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\wsgi_server.py", line 31, in <module>
from cherrypy import wsgiserver
File "C:\Program Files (x86)\Google\google_appengine\lib\cherrypy\cherrypy\__init__.py", line 278, in <module>
_pydoc._builtin_resolve = _pydoc.resolve
AttributeError: 'module' object has no attribute 'resolve'
2014-02-05 10:42:32 (Process exited with code 1)
Also, I'm using Windows 7 x64. My original installation of Python is from Enthought x64, but I did try using the basic x64 Python as well. As mentioned, I downgraded from 1.8.9 to 1.8.8, to no avail.
From a quick Google search, other users are suggesting it's a bug in pyvenv. Since not very many people are still using CherryPy, and it seems to only manifest itself in whatever CherryPy is doing there, that's probably it.
Bug the gist is that somewhere, only on Windows, you have a pydoc.py file which is being imported instead of the standard library's pydoc file.
So, find the offending pydoc.py file in your import path, and rename it. You can most likely find it by doing something like this:
import pydoc
print pydoc.__file__

Twisted under windows

Twisted located at C:\Python26\Lib\site-packages\Twisted-11.0.0-py2.6-win32.egg\twisted
but
C:\projects\webmorda>twistd -n morda_server
Traceback (most recent call last):
File "C:\Python26\Scripts\twistd.py", line 4, in <module>
import pkg_resources
File "C:\Python27\lib\site-packages\pkg_resources.py", line 2671, in <module>
working_set.require(__requires__)
File "C:\Python27\lib\site-packages\pkg_resources.py", line 654, in require
needed = self.resolve(parse_requirements(requirements))
File "C:\Python27\lib\site-packages\pkg_resources.py", line 552, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: twisted==11.0.0
what's wrong?
It looks like you have installed Twisted in a Python 2.6 environment but are using Python 2.7 to run it. I think the following command should work:
C:\Python26\python.exe C:\Python26\Scripts\twistd.py -n morda_server
(It looks like the twistd.py script is being run by the python.exe binary associated with the .py file extension - which in your case appears to be Python 2.7. Alternatively you have a PYTHONPATH environment variable set up to point to the Python 2.7 site-packages directory.)

Problem running python from crontab - "invalid Python installation"

I have python 2.7 installed on my linux box, and I'm trying to schedule a python script via crontab. The script works fine from the command line, however when running via cron I get:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site.py", line 553, in <module>
main()
File "/usr/local/lib/python2.7/site.py", line 535, in main
known_paths = addusersitepackages(known_paths)
File "/usr/local/lib/python2.7/site.py", line 268, in addusersitepackages
user_site = getusersitepackages()
File "/usr/local/lib/python2.7/site.py", line 243, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/local/lib/python2.7/site.py", line 233, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/local/lib/python2.7/sysconfig.py", line 535, in get_config_var
return get_config_vars().get(name)
File "/usr/local/lib/python2.7/sysconfig.py", line 434, in get_config_vars
_init_posix(_CONFIG_VARS)
File "/usr/local/lib/python2.7/sysconfig.py", line 298, in _init_posix
raise IOError(msg)
IOError: invalid Python installation: unable to open /usr/include/python2.7/pyconfig.h (No such file or directory)
I see that /usr/include/python2.7 does't exist, but /usr/local/include/python2.7/ does. Did I make a mistake while installing python?
You probably just have 2 versions installed, one of which is broken. If your cron is just directly calling python instead of a specific path, your PATH probably contains /usr/bin before /usr/local/bin (which is typical) - so in your cron, specify which python to use, or remove the existing one in /usr/bin and symlink /path/to/good/python to /usr/bin/python.
Edit: scratch that, just re-read and saw that it works fine from the command line. python-dev is probably the way to go. Sorry!
You need python2.7-dev, which installs the includes and headers.
For Ubuntu, you run sudo apt-get install python2.7-dev to install it. What Linux distro are you running?
I am assuming that in your crontab file, you are giving the full path to the python executable, and not just relying on she-bang with executable permissions. If not, please give point to the full-path python2.7 in the crontab file and also use the same full-path on the command line to ensure that you don't get this problem.If you get this on command line too, then it is probably missing some development headers. (Are you trying to compile something like using setup.py build and trying to do it via crontab?) I am trying to understand where would one need those headers. So, apart from the above suggestion, extra information from your end might ofcourse help further.

Categories

Resources