Python Forum
Can I make virtualenv (and/or uwsgi) use python 3.6 instead of 2.7?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can I make virtualenv (and/or uwsgi) use python 3.6 instead of 2.7?
#1
I must be doing this wrong:

I'm in ubuntu 18.04.2

I'm figuring out to setup uwsgi according to this:

https://uwsgi-docs.readthedocs.io/en/lat...nginx.html

And it's working so far but it's running python 2.7.15; I want it to run 3.6 (which is already installed on my machine) instead.

When I run virtualenv to make a new environment to run uwsgi in, and I go into the virtualenv the default "python --version" is still python 2.7.15. (Outside of the virtualenv python --version is 3.6)

There's gotta be a way to change that to 3.something right?

Btw I haven't even tried to integrate it with nginx yet, so this is just raw uwsgi.

thanks.
Reply
#2
The solution is to use pyenv (see: https://python-forum.io/Thread-pyenv-Sim...ight=pyenv )
If it's just for one virtual environment version, start a pyenv shell, selecting desired version, and then create the virtual env:

For a test case, assume global python version is 3.8 and you want a virtual environment that uses 3.7.4

From command line:
pyenv shell 3.7.4
python -m venv venv
Once created, you can exit the shell and then just activate the virtual environment normally, the set python version (3.7.4) in this instance will remain, even though your global python version is 3.8 or some other version.

you can globally change the python version to any installed version with:
pyenv global 3.7.4
Reply
#3
Woo! It worked ok here's what I did:

It's kind of a hybrid of the tutorial, your advice, the thread you linked me too, and a line from another forum where I asked this question haha:

sudo apt-get install python3-venv
python3 -m venv ./myapp
cd myapp
source bin/activate
And then subsequently:
uwsgi --socket 0.0.0.0:8080 --protocol=http -w wsgi
And then in the browser it was able to talk to my hello world app.

However what I did wrong (before I posted this post) was; instead of doing nano ~/.bashrc I just overwrote /usr/bin/python /usr/bin/python3

Probably wasn't a good idea, right. I still have the python2 executable so I could just copy /usr/bin/python2 over /usr/bin/python. But I won't bother until something else on the system breaks. (This is on my workstation PC running ubuntu.)

Anyway- all of that git stuff and the .tar.gz file and the "make"- I know how to do that stuff but I figure this is good enough; I don't need something that fancy.

So unless you've got something to add I'll go ahead and mark this solved, yes?

Thanks Larz60.
Reply
#4
pyenv is the way to go.
with is you can install any one of 380+ versions of python
say you wanted miniconda3-4.1.11

symply from command line:
pyenv install miniconda3-4.1.11
Reply
#5
Wait I'm still having the same problem; wsgi is still using 2.7.15

bog@bog-Lenovo-Product:~/myapp/myappdjango/myappdjango$ uwsgi --socket mysite.sock --wsgi-file test.py --chmod-socket=666
*** Starting uWSGI 2.0.18 (64bit) on [Sat Nov  9 00:29:29 2019] ***
compiled with version: 7.4.0 on 15 May 2019 18:53:37
os: Linux-4.15.0-66-generic #75-Ubuntu SMP Tue Oct 1 05:24:09 UTC 2019
nodename: bog-Lenovo-Product
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /home/bog/myapp/myappdjango/myappdjango
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 63335
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address mysite.sock fd 3
Python version: 2.7.15+ (default, Oct  7 2019, 17:39:04)  [GCC 7.4.0]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x564f80b56930
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72904 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x564f80b56930 pid: 32599 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 32599, cores: 1)
But in the venv when I check the python version I get:

(myapp) bog@bog-Lenovo-Product:~/myapp$ python -V
Python 3.6.8
I can't figure out where in the wsgi settings to change that; this is the config file right?

(myapp) bog@bog-Lenovo-Product:~/myapp/myappdjango$ more ./uwsgi_params 

uwsgi_param  QUERY_STRING       $query_string;
uwsgi_param  REQUEST_METHOD     $request_method;
uwsgi_param  CONTENT_TYPE       $content_type;
uwsgi_param  CONTENT_LENGTH     $content_length;

uwsgi_param  REQUEST_URI        $request_uri;
uwsgi_param  PATH_INFO          $document_uri;
uwsgi_param  DOCUMENT_ROOT      $document_root;
uwsgi_param  SERVER_PROTOCOL    $server_protocol;
uwsgi_param  REQUEST_SCHEME     $scheme;
uwsgi_param  HTTPS              $https if_not_empty;

uwsgi_param  REMOTE_ADDR        $remote_addr;
uwsgi_param  REMOTE_PORT        $remote_port;
uwsgi_param  SERVER_PORT        $server_port;
uwsgi_param  SERVER_NAME        $server_name;
None of that looks like someplace to change python versions. So where is it set on using 2.7?

thanks
Reply
#6
did you activate the virtual environment?
from command line (Linux), command is:
. ./venv/bin/activate
check with
Python -V
Reply
#7
(Nov-09-2019, 11:02 AM)Larz60+ Wrote: did you activate the virtual environment?
from command line (Linux), command is:
. ./venv/bin/activate
check with
Python -V

You know what's really odd- suddenly I can't reproduce the results I pasted in my last question. I mean either when I'm in the venv or not. That makes no sense.

The only thing I can think of is that I had logged out of my session (as in the entire ubuntu session, not just CLI login). Would that change anything?

Anyway now I get:

Python version: 3.6.8 (default, Oct 7 2019, 12:59:55) [GCC 8.3.0]

I have this sinking feeling 2.7 will come back somehow...

Thanks
Reply
#8
Quote:The only thing I can think of is that I had logged out of my session (as in the entire ubuntu session, not just CLI login). Would that change anything?
Always possible, if you have a lot of zomibe processes or other junk lying around.

I usually check for zombies after any long session, here's a good blog on that: https://www.servernoobs.com/how-to-find-...processes/

A great tool that I use many times a day is bleach bit, and of course, it's free... But be VERY careful, it will do exactly what you ask it to do and that could lead to disaster.

If you're not totally comfortable using it, don't, period.

Totally backup before using the first time. Once it's setup, it never has to be changed unless you change your distro. Also, I have never used it on MS Windows (haven't actually used MS windows for several years).
Reply
#9
(Nov-10-2019, 02:50 AM)Larz60+ Wrote:
Quote:The only thing I can think of is that I had logged out of my session (as in the entire ubuntu session, not just CLI login). Would that change anything?
Always possible, if you have a lot of zomibe processes or other junk lying around.

I usually check for zombies after any long session, here's a good blog on that: https://www.servernoobs.com/how-to-find-...processes/

A great tool that I use many times a day is bleach bit, and of course, it's free... But be VERY careful, it will do exactly what you ask it to do and that could lead to disaster.

If you're not totally comfortable using it, don't, period.

Totally backup before using the first time. Once it's setup, it never has to be changed unless you change your distro. Also, I have never used it on MS Windows (haven't actually used MS windows for several years).

Oh wow that link is amazing, I'm bookmarking it, all that process snooping stuff.

Bleach bit- I thought that was for the hard drive; it has something to do with processes in memory too? (I thought bleach bit was what hillary used to wipe the hard drive during the email server scandal right? It's a hard drive wiping tool?)

Anyway thanks- and btw I haven't used windows (or macos) in years either. I'll install them in virtual box when I get around to it.

thanks again
Reply
#10
Bleachbit does cleans and memory as well (if you configure it to do so)
Again, I wouldn't use it unless you really have a very good knowledge of Linux, I actually shouldn't have mentioned it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What do I put in the "module" argument in a uwsgi.ini file? david503 0 2,473 Nov-10-2019, 04:00 AM
Last Post: david503
  How to point a subdomain to run applications using virtualenv on ec2 (AWS) JohnnyCoffee 0 1,350 Oct-02-2019, 12:43 AM
Last Post: JohnnyCoffee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020