I have a local Django application that I've been developing for a while. Today, after about a month off from working on it I went back to it, but it wouldn't load. Checking the apache error log, I see the following over and over:
Current thread 0x00007fffc0be23c0 (most recent call first):
[Tue Sep 26 19:18:09.154141 2017] [core:notice] [pid 1590] AH00052: child pid 1651 exit signal Abort trap (6)
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
The last time I was working on the project, I made some changes to my project code, but didn't touch and of my apache or mod_wsgi configuration.
My PYTHONPATH is not set (nor was it set a month ago when everything was working. Here's my mod_wsgi configs (again haven't changed):
WSGIDaemonProcess secureDash python-path=/Users/user/projects/secureDash_project python-home=/Users/user/.venvs/securedash_py3.6
WSGIProcessGroup secureDash
WSGIScriptAlias / /Users/user/projects/secureDash_project/config/wsgi.py
I've spent a lot of time googling this issue, but none of the common fixes seem to apply. Looking for some guidance on where else to look.
I discovered that, while in my virtualenv:
workon securedash_py3.6
I got an error trying to run the python console:
(securedash_py3.6) user conf $ python3
dyld: Library not loaded: #executable_path/../.Python
Referenced from: /Users/user/.venvs/securedash_py3.6/bin/python3
Reason: image not found
Abort trap: 6
Searching that error pointed me to this SO topic that eventually resolved my issue. Basically I had done some stuff with homebrew that must have broken the symlinks in my venv. Here are the specific commands that I read to resolve:
find ~/.venvs/securedash_py3.6/ -type l -delete
Then cd to the virtualenv directory:
$ cd ~/.venvs/securedash_py3.6
$ virtualenv .
Using base prefix '/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6'
Overwriting /Users/user/.venvs/securedash_py3.6/lib/python3.6/orig-prefix.txt with new content
New python executable in /Users/user/.venvs/securedash_py3.6/bin/python3.6
Also creating executable in /Users/user/.venvs/securedash_py3.6/bin/python
Installing setuptools, pip, wheel...done.
And all is well.
Related
When trying to run a program in python from the terminal I get the following error:
Fatal Python error: Py_Initialize: unable to load the file system codec
LookupError: no codec search functions registered: can't find encoding
Current thread 0x00007fffb68a93c0 (most recent call first):
Abort trap: 6
I am currently running Python 3.6.4 :: Anaconda custom (64-bit) and think this problem may have to do with also having Anaconda 2 installed. Could someone help me figure out what the cause is and how I can remedy this?
I'd also be interested in knowing more tips about how to use Anaconda 2 and 3 concurrently so that this doesn't happen again.
After some trouble shooting w/ you, it looks like reinstalling anaconda (from the version 3.6 choice on the web) crossed some wires.
For others either...
1) Use your original installment and make a python3 environment. To do this change your .bash_profile to only include
export PATH="/Users/<username>/anaconda2/bin:$PATH
and perhaps remove or move the
/Users/<username>/anaconda3
directory to a new name. Then make a new environment using the original anaconda(with python version 2) that fetches and uses Python 3.6:
conda create -n mypython3environment python=3.6
where "mypython3environment" is some name you want when you use python 3.6
then to use it in your project - go to your project's directory and type:
source activate mypython3environment
2) Do a clean install. The other option is to cut out the anaconda stuff from your .bash_profile, remove or move the anaconda2/ and anaconda3 directories and the .bash_profile.pysave file and try to reinstall from the anaconda webpage.
Overall - you need to install anaconda once - then use conda create and source activate <environment name> to make then use environments, respectively, with your Python version of choice, whether it is a Python 2 or 3 version.
See Anaconda's Managing Environments and the cheatsheet
I have Python 2.7 operating correctly on Windows. I installed 2.6 in another folder. However, when I run 2.6 in IDLE or PowerShell, it does not recognize basic commands and cannot import installed libraries. Whenever I launch 2.6, the first thing that comes up is:
'import site' failed; use -v for traceback
I can't find anything on this error aside from some mentions with specific libraries. Trying again using -v suggests 2.6 is pulling libraries from 2.7 which is causing some of the errors.
It then launches, but doesn't recognize installed libraries. For example:
import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
Similarly, simple commands like quit() or help result in:
Traceback (most recent call last): File "", line 1, in
NameError: name 'help' is not defined
I have tried reinstalling 2.6 and double-checked the registries are pointing to the right places. Virtualenv can't seem to run it either, so I'd like a solution that doesn't involve it...for now.
EDIT:
Running 2.6 with -v starts off like this:
PS C:\python26> python26 -v
installing zipimport hook
import zipimport # builtin
installed zipimport hook
C:\Python27\Lib\site.pyc matches >C:\Python27\Lib\site.py
import site # precompiled from >C:\Python27\Lib\site.pyc
For some reason, zipimport is pulling from 2.7, not 2.6.
I found a text_zipimport.py file, but it's beyond me.
Took a while, but I did solve this. When I installed 2.6, it did not add anything to the environment path. I'm working in windows, so here's what I did:
Start -> search for "environment"
Select "Edit environment variables for your account"
Click the variable Path and click Edit
Add "C:\Python26;C:\Python26\Scripts;" to the path
Ok
After that it loads properly.
I'm, working on Windows 8 and I receive this error when launching my python program on pycharm:
ImportError: No module named Qwt5
refered to the line: "import PyQt4.Qwt5 as Qwt"
the program always worked till today, and the IDE still suggests me Qwt5 as a module to import when pressing CTRL+SPACE, so it seems is still recognized.
I checked the Qwt5 folder and there is the __init__.py file
I use Python 2.7.9 an is correctly selected as Python Interpreter
I've already tried to remove the packages and reinstall them.
Someone can help me?
i tried this and working.sudo apt-get install python-qwt5-qt4
I have downloaded the Reindent-0.1.0 and trying to use this for automated indention purpose.
I don't know how to install and run these commands and while I am trying to use this command
I am getting following error
command:
C:\Python26\Scripts\Reindent-0.1.0>Python setup.py
C:\Python26\Scripts\Reindent-0.1.0>Pyth
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from setuptools import setup
ImportError: No module named setuptools
I don't understand the setuptools, where it is and how to put inside
please note my folder files in Reindent-0.1.0
Reindent.egg-info
PKG-INFO
README
reindent
setup.cfg
setup.py
Also how can I run the commands for reindent, for an example, once after I installed the reindent, if I want to
run dryrun command how I should write?
If I write like this, will it be correct ???
C:\ProjFolder\ApplicationDevelopment\GUI>reindent -d Test.py
some realtime example of "-d (--dryrun) Dry run and -r (--recurse) Recurse" will be helpful!!
and where I should target the command file path, in dos
to my application running directory or C:\Python26\Scripts\Reindent-0.1.0 ?? OR Application development folder??
If you get the error "no module X" when you try to run some code, that code has a dependency on module X. When you run setup.py and it says there is no module named "setuptools", it is telling you that setup.py requires the module "setuptools". Since you don't have "setuptools" installed on your machine, you get the error.
The fix is simple: install the setuptools module. Here's one of several places on the internet that shows you how to install setuptools: https://pythonhosted.org/an_example_pypi_project/setuptools.html
I run at a cloned Django repository
python manage.py runserver
I get
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
The problem is in my PYTHONPATH according to MacPorts' IRC.
I run
ls -l $(which python)
I get
lrwxr-xr-x 1 root wheel 68B Jan 29 12:27 /usr/local/bin/python -> ../../../Library/Frameworks/Python.framework/Versions/2.6/bin/python
This command suggests according to krunk that my PATHs are incorrect: /opt/local/... should be before /usr/local/...
However, I am not sure what he means.
My PYTHONPATH in ~/.zshrc is
export PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.6/:$HOME/.python_libraries:
where /opt/local/... is the first PATH as krunk suggests.
I run
which $PYTHONPATH
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/:/Users/Sam/.python_libraries: not found
My PYTHONPATH has something wrong: apparently the /opt/locall/... is not right.
How can you get the PYTHONPATH correct?
Your problem is not with PYTHONPATH, it's with PATH itself -- echo $PATH to see it, export PATH=whatever to change it (you can do that in your ~/.bashrc for example).
You'll see that in your current PATH /usr/local/bin comes before /opt/local/bin -- you need to swap them if you want python to be running from your MacPorts. Alternatively, of course, you can choose to explicitly run /opt/local/bin/python ...
I would recommend not using macports, and install Python using Jesse Noller's instructions at http://jessenoller.com/2009/03/16/so-you-want-to-use-python-on-the-mac/
His instructions assume Bash, but should work the same for zsh.