Fatal Python error: PyEval_AcquireThread - django

I just put up a django application online and i'm getting this error in my error log
Fatal Python error: PyEval_AcquireThread: NULL new thread state
I have seen a few similar questions online, but they do not explain this error.

The problem can appear if apache mod_wsgi and mod_python are both enabled.
Try
sudo a2dismod python
sudo service apache2 restart

This tends to indicate that your mod_wsgi is compiled for a different Python version and/or a different Python installation than the Python virtual environment or Python installation it is trying to use at runtime.
In other words, you are mixing compiled shared library and extension modules from different Python installations. This can cause all sorts of problems.
Go through the checks in:
http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation
to understand how your mod_wsgi has been built and verify it is what you expect it to be.

In my case it was permissions for the directories where Django or Flask project are. They were created from root, so I changed them to www-data in my case.

Related

Django installation dependency errors after rolling back to Python 3.7.6

I'm working my way through the tutorials in William S. Vincent's Django for Beginners. Everything worked fine until Chapter 4 (the Message Board app), when like a nOOb I ran into the known bug that causes Django's web server to crash when attempting to serve /admin/ using Python 3.7.* in pipenv. So, I upgraded Python to 3.8.2, and it still didn't work. So I foolishly deleted 3.8.2 and rolled back to 3.7.6, and now I can't install Django at all with pipenv due to a variety of pipenv.exceptions.ResolutionFailure statements.
I've reinstalled Python 3.7.6 AND 3.8.2, pip3, pipenv and Django (through Anaconda as well as outside of it), but I'm still getting the same litany of errors that won't let Django be installed in my virtual environment. Using pipenv lock --pre --clear doesn't fix it.
The telling line is "ERROR: No matching distribution found for django-3-0"
Does anyone have any idea how to resolve this or what packages I need to uninstall/reinstall?
Thanks much! :)
Manually delete the whole pipenv cache directory,
~/.cache/pipenv - (Linux)
%LOCALAPPDATA%\pipenv\pipenv\Cache - (Windows)
Also delete the previous virtualenvs which were created within the .virtualenvs folder. (or the entire folder)
Default location: C:\Users\{username}\.virtualenvs
Also delete Pipfile.lock file and then recreate your virtual environment:
pipenv shell
Well, good news! On a hunch, and to rule-out any weirdness, I tried recreating a clean Django install by using virtualenv, since pipenv is giving me problems. It worked! I must have borked something with pipenv when I removed/re-added/re-removed Python 8.x. Thanks for your inspiration for this workaround, #Magicoder!

how to handle this syntax error in django project

I have transferred my Django project onto Linode server already. The project was developed in VS, within anaconda (base) environment on my Mac.
After I downloaded it onto the Linode server when activating it, it gave me too many dependencies (not all needed it seemed). One of them prevented me from completing the process.
So, I sudo installed (in venv) needed packages (within the project’s virtual environment), for example:
certifi,
chardet,
Django…,
After creating ’static’ in the settings.py, on the linode server, I tried to collect static :
~$ python manage.py collectstatic
BUT I am getting this Error message:
/home/..../django/users/models.py", line 16
return f'{self.user.username} Profile'
^
SyntaxError: invalid syntax
What is wrong here? How can I fix this error?
Check your python version. f strings are a fairly new feature, introduced with python 3.6. It's likely that you run an older version.

Bitnami Django Stack - not importing modules

I just tried deploying my Django application on my windows machine using Bitnami's Django stack. However, when I try to access my project via localhost/myapp/, I get an error stating that I can't load my modules/python libraries. I checked via pip and I have these modules installed. It seems this error applies to all my modules/python libraries. How do I solve this? Thanks!
When you install the Bitnami Django Stack, it will ask you for changing Association Setting for Python with the following message:
"This option lets you change the Windows properties to associate the Python files to the new Python that are going to be installed. If you have your own Python you may want to disable this feature."
If you decided to use your Python instead of the one that is installed with the Stack, you have must ensure that you have installed Python in your system and all the modules and libraries are loaded, otherwise you won't be able to use any of them.

Configure Web2Py to use Anaconda Python

I am new to Web2Py and Python stack. I need to use a module in my Web2Py application which uses "gensim" and "nltk" libraries. I tried installing these into my Python 2.7 on a Windows 7 environment but came across several errors due to some issues with "numpy" and "scipy" installations on Windows 7. Then I ended up resolving those errors by uninstalling Python 2.7 and instead installing Anaconda Python which successfully installed the required "gensim" and "nltk" libraries.
So, at this stage I am able to see all these "gensim" and "nltk" libraries resolving properly without any error in "Spyder" and "PyCharm". However, when I run my application in Web2Py, it still complains about "gensim" and gives this error: <type 'exceptions.ImportError'> No module named gensim
My guess is if I can configure Web2Py to use the Anaconda Python then this issue would be resolved.
I need to know if it's possible to configure Web2Py to use Anaconda Python and if it is then how do I do that?
Otherwise, if someone knows of some other way resolve that "gensim" error in Web2Py kindly share your thoughts.
All your help would be highly appreciated.
The Windows binary includes it's own Python interpreter and will therefore not see any packages you have in your local Python installation.
If you already have Python installed, you should instead run web2py from source.

Django: Setting up apps on a server

Trying to upload my django app on my obunto slice. The problem I'm facing right now there are a couple of packages I'm using. Which I installed in site packages on my machine. Now when I put them online on the server their sadly not working. Any ideas how to make them work.
p.s I get a error on import
Python must have a way to find these packages. Did you use standard installation procedures for them (i.e. setup.py install) or copy them in an accessible directory? If you didn't use setup.py install, check your PYTHONPATH environment variable. It should contain the directory where your packages are stored. If it doesn't, you can create it.
This is a Python issue really, not a Django issue.
To get more help paste the import error you're getting, as well as the directory structure of where you installed this package.