web2py with python 2.7 and web2py running on python 3

195 views
Skip to first unread message

Andrea Fae'

unread,
Mar 14, 2020, 3:06:20 PM3/14/20
to web2py-users
Is it possible to have 2 differents environment on the same PC?
web2py running python2.7 and web2py running ppython 3 separated...?
Thank you 

Tim Nyborg

unread,
Mar 20, 2020, 7:34:10 AM3/20/20
to web2py-users
Should be, but it can depend on what other tools you're using in web stack.  E.g., the steps it'll take to get Apache running two different environments are different from the steps to get NGINX/Uwsgi, or Gunicorn.

Jonathan Clark

unread,
Mar 20, 2020, 5:05:59 PM3/20/20
to web2py-users
Definitely if you're using the rocket web server. There are various ways to run different versions of python on the same machine but it depends on your OS how to do it. Once you can run different pythons, you can run different versions of web2py at the same time, but you will need to use different ports e.g. 8080, 8081 etc. to direct the traffic to the right web2py instance. That's without Apache.

I also run different web2py instances behind the same Apache instance on a virtual host, but I have set up Apache to forward virtual host one to one port (using .htaccess), and virtual host two to a different port. The rocket server in web2py in each instance is told which port it should respond to. So the browser looks for www.hostone.com, .htaccess forwards that to port number 65789, and a web2py instance is run to service requests to port 65789. For hosttwo, the port number changes.

Here is a snippet of a .htacces file which does what I want:

RewriteCond %{HTTP_HOST}  hostone.com$
RewriteRule ^(.*)$        https://127.0.0.1:65789/$1 [P,QSA,L]

(There is another redirect which directs www.hostone.com to hostone.com).


On Saturday, 14 March 2020 19:06:20 UTC, Andrea Fae' wrote:

Andrea Fae'

unread,
Mar 21, 2020, 4:59:59 PM3/21/20
to web2py-users
I have a windows 10 PC.
I installed c:\python27 and c:\python3 and they are working. I can choose.

But if I try to start web2py it happens this error:

c:\Python3>python.exe c:\web2py\web2py.py
Traceback (most recent call last):
  File "c:\web2py\web2py.py", line 21, in <module>
    import gluon.widget
  File "c:\web2py\gluon\__init__.py", line 37, in <module>
    from .globals import current
  File "c:\web2py\gluon\globals.py", line 24, in <module>
    from gluon.serializers import json, custom_json
  File "c:\web2py\gluon\serializers.py", line 10, in <module>
    from gluon.languages import lazyT
  File "c:\web2py\gluon\languages.py", line 19, in <module>
    from cgi import escape
ImportError: cannot import name 'escape' from 'cgi' (c:\Python3\lib\cgi.py)

I found that changing "from cgi import escape" to "from html import escape" it start but I don't knoy why.

Nevertheless If I try to start an app built from Python27 I have this error:

<type 'exceptions.RuntimeError'> Failure to connect, tried 5 times: Traceback (most recent call last): File "C:\web2py\gluon\packages\dal\pydal\base.py", line 454, in __init__ self._adapter = adapter(**kwargs) File "C:\web2py\gluon\packages\dal\pydal\adapters\__init__.py", line 40, in __call__ obj = super(AdapterMeta, cls).__call__(*args, **kwargs) File "C:\web2py\gluon\packages\dal\pydal\adapters\base.py", line 368, in __init__ super(SQLAdapter, self).__init__(*args, **kwargs) File "C:\web2py\gluon\packages\dal\pydal\adapters\base.py", line 52, in __init__ self.reconnect() File "C:\web2py\gluon\packages\dal\pydal\connection.py", line 172, in reconnect self.connection = self.connector() File "C:\web2py\gluon\packages\dal\pydal\adapters\mysql.py", line 52, in connector return self.driver.connect(**self.driver_args) File "C:\web2py\gluon\contrib\pymysql\__init__.py", line 90, in Connect return Connection(*args, **kwargs) File "C:\web2py\gluon\contrib\pymysql\connections.py", line 688, in __init__ self.connect() File "C:\web2py\gluon\contrib\pymysql\connections.py", line 905, in connect self._get_server_information() File "C:\web2py\gluon\contrib\pymysql\connections.py", line 1231, in _get_server_information self.server_charset = charset_by_id(lang).name File "C:\web2py\gluon\contrib\pymysql\charset.py", line 38, in by_id return self._by_id[id] KeyError: 255


If I start the same app with web2py on python 2.7 changing back to "from cgi import escape" and it's working.
Maybe this is a problem regarding foreign-keys, I had one time in the past but.... really... I don't remember how to fix.

Thank you

Dave S

unread,
Mar 26, 2020, 12:48:51 AM3/26/20
to web2py-users


On Saturday, March 21, 2020 at 1:59:59 PM UTC-7, Andrea Fae' wrote:
I have a windows 10 PC.
I installed c:\python27 and c:\python3 and they are working. I can choose.

But if I try to start web2py it happens this error:

c:\Python3>python.exe c:\web2py\web2py.py
Traceback (most recent call last):
  File "c:\web2py\web2py.py", line 21, in <module>
    import gluon.widget
  File "c:\web2py\gluon\__init__.py", line 37, in <module>
    from .globals import current
  File "c:\web2py\gluon\globals.py", line 24, in <module>
    from gluon.serializers import json, custom_json
  File "c:\web2py\gluon\serializers.py", line 10, in <module>
    from gluon.languages import lazyT
  File "c:\web2py\gluon\languages.py", line 19, in <module>
    from cgi import escape
ImportError: cannot import name 'escape' from 'cgi' (c:\Python3\lib\cgi.py)

I found that changing "from cgi import escape" to "from html import escape" it start but I don't knoy why.

Nevertheless If I try to start an app built from Python27 I have this error:

<type 'exceptions.RuntimeError'> Failure to connect, tried 5 times: Traceback (most recent call last): File "C:\web2py\gluon\packages\dal\pydal\base.py", line 454, in __init__ self._adapter = adapter(**kwargs) File "C:\web2py\gluon\packages\dal\pydal\adapters\__init__.py", line 40, in __call__ obj = super(AdapterMeta, cls).__call__(*args, **kwargs) File "C:\web2py\gluon\packages\dal\pydal\adapters\base.py", line 368, in __init__ super(SQLAdapter, self).__init__(*args, **kwargs) File "C:\web2py\gluon\packages\dal\pydal\adapters\base.py", line 52, in __init__ self.reconnect() File "C:\web2py\gluon\packages\dal\pydal\connection.py", line 172, in reconnect self.connection = self.connector() File "C:\web2py\gluon\packages\dal\pydal\adapters\mysql.py", line 52, in connector return self.driver.connect(**self.driver_args) File "C:\web2py\gluon\contrib\pymysql\__init__.py", line 90, in Connect return Connection(*args, **kwargs) File "C:\web2py\gluon\contrib\pymysql\connections.py", line 688, in __init__ self.connect() File "C:\web2py\gluon\contrib\pymysql\connections.py", line 905, in connect self._get_server_information() File "C:\web2py\gluon\contrib\pymysql\connections.py", line 1231, in _get_server_information self.server_charset = charset_by_id(lang).name File "C:\web2py\gluon\contrib\pymysql\charset.py", line 38, in by_id return self._by_id[id] KeyError: 255


If I start the same app with web2py on python 2.7 changing back to "from cgi import escape" and it's working.
Maybe this is a problem regarding foreign-keys, I had one time in the past but.... really... I don't remember how to fix.

Thank you


Make sure you have separate directories for running under python 2.7 and  python 3.x.
Files get compiled, and the .pyc is not portable between the two versions.

/dps

Jobin Antony

unread,
Mar 30, 2020, 2:33:40 AM3/30/20
to web2py-users
c:\web2py>c:\python27\python.exe web2py.exe
  File "web2py.exe", line 1
SyntaxError: Non-ASCII character '\x90' in file web2py.exe on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

c:\web2py>

Jobin Antony

unread,
Mar 30, 2020, 2:35:19 AM3/30/20
to web2py-users


C:\Users\Jobin>cd c:\web2py

c:\web2py>c:\python27\python.exe web2py.py
Traceback (most recent call last):
  File "web2py.py", line 8, in <module>
    from multiprocessing import freeze_support
  File "c:\python27\lib\multiprocessing\__init__.py", line 83, in <module>
    import _multiprocessing
ImportError: DLL load failed: %1 is not a valid Win32 application.

c:\web2py>

Massimo Di Pierro

unread,
Apr 26, 2020, 1:23:09 AM4/26/20
to web2py-users
Reply all
Reply to author
Forward
0 new messages