4

I have a server with FreeBSD 10.1 installed. I want to deploy a Django site on it using uwsgi+nginx+python3 and got some problems.

The site was written for python3, I installed python3.4 then python3 and python from ports, configured nginx and wrote uwsgi ini-file and sock-file. I then tried to start the project. It works perfecttly in virtualenv.

Then I installed uwsgi globally using pip3. But when I try to start the project globally I get the error

no module named site

which means that uwsgi uses python2 instead of 3. What I tried to resolve this problem:

  • set DEFAULT_VERSIONS=python=3.4 in make.conf;
  • set $PYTHONHOME and $PYTHONPATH to /usr/local/bin/python3;
  • change link /usr/local/bin/python from python2 to python3;

It didn't help. How to force uwsgi to use python3 instead of python2?

PS photo of terminal: http://prntscr.com/9os1f2

  • It looks like uwsgi sets PythonPath when it runs, presumably for its own bundled version of Python. I don't use uwsgi so I don't know for sure, but there should be either a) a setting to change that or b) manually replace their Python 2 executable with a symlink to your Python 3 executable. – gardenhead Jan 11 '16 at 17:35
  • 2
    When setting DEFAULT_VERSIONS=python=3.4 in make.conf what exactly did you do? Did you rebuild the port? – Raphael Ahrens Jan 12 '16 at 10:26
  • This ^^ ... it should help set a compile-time option; something akin to 'CFLAGS="-I/usr/local/include/python3.4" make PYTHON=python3.4 asyncio' ... if the port hasn't been rebuilt, that's the first thing to try. make.conf should take over and set the flags for you. – Kevin_Kinsey Jan 13 '16 at 17:49
  • @Raphael You're right, I forgot to rebuilt the port after changing make.conf. Foolishly, but I'm new in UNIX. Add you comment to answers and I'll commit it. – DiA Jan 14 '16 at 10:55
  • @DiA I added my answer so it is easier to spot. – Raphael Ahrens Jan 15 '16 at 16:56
3

When setting

DEFAULT_VERSIONS=python=3.5 python2=2.7 python3=3.5

in /etc/make.conf you have to rebuild the ports that use the default version of Python.

0

You can use virtualenv to handle different Python versions on one server, and use completely separate Python installations for whatever you need.

See http://docs.python-guide.org/en/latest/dev/virtualenvs/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.