![]() |
python -m venv VS virtualenv - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: python -m venv VS virtualenv (/thread-19711.html) |
python -m venv VS virtualenv - kazi380 - Jul-11-2019 Hi all, Can someone explain to me why Apache24 server is able to host my Python-Flask (test) web application, when the Python virtual environment is created with 'virtualenv' but NOT when the Python virtual environment is created with 'python -m venv'? Preferably i would also like to learn how to make the Python virtual environment, created with 'python -m venv', work with Apache24. My system setup: Windows 10 64-bit Microsoft Visual C++ 2015-2019 Redistributable (x64) Microsoft Visual build tools C++ version 14.0.25420.1 Apache 2.4.39 Win64 (VC14 from Apache Lounge, installation path C:\Apache24) Python 3.6.0 64-bit (installation path C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64) Python 3.6.0 64-bit Virtual Environment (installation path C:\myenv) mod_wsgi 4.6.7 flask 1.1.1 Procedure for creating the Python virtual environment (myenv01) with 'virtualenv': 1. C:\>virtualenv myenv01 2. C:\myenv01\Scripts>activate 3. C:\myenv01\Scripts>python -m pip install --upgrade pip setuptools wheel 4. C:\myenv01\Scripts>pip install mod_wsgi 5. C:\myenv01\Scripts>pip3 install flask 6. C:\myenv01\Scripts>deactivate Procedure for creating the Python virtual environment (myenv02) with 'python -m venv': 1. C:\>phyton -m venv myenv02 2. C:\myenv02\Scripts>activate 3. C:\myenv02\Scripts>python -m pip install --upgrade pip setuptools wheel 4. C:\myenv02\Scripts>pip install mod_wsgi 5. C:\myenv02\Scripts>pip3 install flask 6. C:\myenv02\Scripts>deactivate I already did some investigation myself by comparing the two virtual environments. It turned out that the 'python -m venv' environment is missing some critical files needed for the Python-Flask web application to work with Apache24. So far I have pinpointed the issue to files missing in "C:\myenv02\Lib" and a missing folder "C:\myenv02\Lib\encodings". When I copy these files and folder from the 'virtualenv' environment (myenv01) to the 'python -m venv' environment (myenv02), Apache24 is also able to host the web application with the 'python -m venv' environment (myenv02). Unfortunately due to my lack of Python knowledge I have difficulty to understand what these files are for and what purpose they have in the hosting of the Python-flask web application. At this moment I think they are just some basic Python modules/scripts but am puzzled why they aren't created with the 'python -m venv' command. Directory C:\myenv02\Lib 11-07-2019 12:38 <DIR> site-packages 11-07-2019 12:27 <DIR> tcl8.6 Directory C:\myenv01\Lib 16-05-2016 16:43 8,628 abc.py 11-09-2016 22:51 20,418 base64.py 16-05-2016 16:43 2,595 bisect.py 16-05-2016 16:43 36,231 codecs.py 10-07-2019 18:26 <DIR> collections 14-06-2016 00:47 8,815 copy.py 16-05-2016 16:43 6,833 copyreg.py 11-07-2019 12:41 <DIR> distutils 10-07-2019 18:26 <DIR> encodings 22-11-2016 00:14 33,000 enum.py 11-09-2016 22:51 3,166 fnmatch.py 11-09-2016 22:51 30,967 functools.py 05-09-2016 19:43 4,756 genericpath.py 07-09-2016 16:50 9,477 hashlib.py 16-05-2016 16:43 22,929 heapq.py 11-09-2016 22:51 5,057 hmac.py 15-08-2016 18:35 10,624 imp.py 10-07-2019 18:26 <DIR> importlib 11-09-2016 22:51 3,517 io.py 16-05-2016 16:43 2,211 keyword.py 16-05-2016 16:43 5,312 linecache.py 14-06-2016 00:47 74,724 locale.py 11-07-2019 12:41 0 no-global-site-packages.txt 07-09-2016 16:50 23,148 ntpath.py 16-05-2016 16:43 10,863 operator.py 11-07-2019 12:41 65 orig-prefix.txt 22-11-2016 00:15 37,442 os.py 05-09-2016 19:43 15,349 posixpath.py 22-11-2016 00:15 27,228 random.py 14-11-2016 20:25 15,552 re.py 16-05-2016 16:43 5,336 reprlib.py 14-06-2016 00:47 7,097 rlcompleter.py 01-11-2016 02:21 40,086 shutil.py 11-07-2019 12:58 <DIR> site-packages 11-07-2019 12:41 28,389 site.py 11-09-2016 22:51 19,338 sre_compile.py 16-05-2016 16:43 6,448 sre_constants.py 07-12-2016 04:27 36,422 sre_parse.py 16-05-2016 16:43 5,038 stat.py 16-05-2016 16:43 257 struct.py 01-11-2016 02:21 93,021 tarfile.py 14-06-2016 00:47 26,635 tempfile.py 16-05-2016 16:43 3,075 token.py 11-09-2016 22:51 28,959 tokenize.py 11-09-2016 22:51 8,870 types.py 07-12-2016 04:27 18,488 warnings.py 16-05-2016 16:43 19,408 weakref.py 16-05-2016 16:43 1,301 _bootlocale.py 22-11-2016 00:14 26,253 _collections_abc.py 16-05-2016 16:43 5,118 _dummy_thread.py 16-05-2016 16:43 5,705 _weakrefset.py 16-05-2016 16:43 4,841 __future__.py 11-07-2019 12:41 <DIR> __pycache__ Directory of C:\myenv01\Lib\encodings 07-09-2016 16:50 15,577 aliases.py 16-05-2016 16:43 1,248 ascii.py 16-05-2016 16:43 1,533 base64_codec.py 16-05-2016 16:43 1,019 big5.py 16-05-2016 16:43 1,039 big5hkscs.py 16-05-2016 16:43 2,249 bz2_codec.py 16-05-2016 16:43 2,084 charmap.py 16-05-2016 16:43 13,121 cp037.py 16-05-2016 16:43 13,568 cp1006.py 16-05-2016 16:43 13,113 cp1026.py 16-05-2016 16:43 34,597 cp1125.py 16-05-2016 16:43 13,105 cp1140.py 16-05-2016 16:43 13,686 cp1250.py 16-05-2016 16:43 13,361 cp1251.py 16-05-2016 16:43 13,511 cp1252.py 16-05-2016 16:43 13,094 cp1253.py 16-05-2016 16:43 13,502 cp1254.py 16-05-2016 16:43 12,466 cp1255.py 16-05-2016 16:43 12,814 cp1256.py 16-05-2016 16:43 13,374 cp1257.py 16-05-2016 16:43 13,364 cp1258.py 16-05-2016 16:43 14,132 cp273.py 16-05-2016 16:43 12,055 cp424.py 16-05-2016 16:43 34,564 cp437.py 16-05-2016 16:43 13,121 cp500.py 16-05-2016 16:43 1,106 cp65001.py 16-05-2016 16:43 13,686 cp720.py 16-05-2016 16:43 34,681 cp737.py 16-05-2016 16:43 34,476 cp775.py 16-05-2016 16:43 34,105 cp850.py 16-05-2016 16:43 35,002 cp852.py 16-05-2016 16:43 33,850 cp855.py 16-05-2016 16:43 12,423 cp856.py 16-05-2016 16:43 33,908 cp857.py 16-05-2016 16:43 34,015 cp858.py 16-05-2016 16:43 34,681 cp860.py 16-05-2016 16:43 34,633 cp861.py 16-05-2016 16:43 33,370 cp862.py 16-05-2016 16:43 34,252 cp863.py 16-05-2016 16:43 33,663 cp864.py 16-05-2016 16:43 34,618 cp865.py 16-05-2016 16:43 34,396 cp866.py 16-05-2016 16:43 32,965 cp869.py 16-05-2016 16:43 12,595 cp874.py 16-05-2016 16:43 12,854 cp875.py 16-05-2016 16:43 1,023 cp932.py 16-05-2016 16:43 1,023 cp949.py 16-05-2016 16:43 1,023 cp950.py 16-05-2016 16:43 1,051 euc_jisx0213.py 16-05-2016 16:43 1,051 euc_jis_2004.py 16-05-2016 16:43 1,027 euc_jp.py 16-05-2016 16:43 1,027 euc_kr.py 16-05-2016 16:43 1,031 gb18030.py 16-05-2016 16:43 1,027 gb2312.py 16-05-2016 16:43 1,015 gbk.py 16-05-2016 16:43 1,508 hex_codec.py 16-05-2016 16:43 13,475 hp_roman8.py 16-05-2016 16:43 1,011 hz.py 16-05-2016 16:43 9,170 idna.py 16-05-2016 16:43 1,053 iso2022_jp.py 16-05-2016 16:43 1,061 iso2022_jp_1.py 16-05-2016 16:43 1,061 iso2022_jp_2.py 16-05-2016 16:43 1,073 iso2022_jp_2004.py 16-05-2016 16:43 1,061 iso2022_jp_3.py 16-05-2016 16:43 1,069 iso2022_jp_ext.py 16-05-2016 16:43 1,053 iso2022_kr.py 16-05-2016 16:43 13,176 iso8859_1.py 16-05-2016 16:43 13,589 iso8859_10.py 16-05-2016 16:43 12,335 iso8859_11.py 16-05-2016 16:43 13,271 iso8859_13.py 16-05-2016 16:43 13,652 iso8859_14.py 16-05-2016 16:43 13,212 iso8859_15.py 16-05-2016 16:43 13,557 iso8859_16.py 16-05-2016 16:43 13,404 iso8859_2.py 16-05-2016 16:43 13,089 iso8859_3.py 16-05-2016 16:43 13,376 iso8859_4.py 16-05-2016 16:43 13,015 iso8859_5.py 16-05-2016 16:43 10,833 iso8859_6.py 16-05-2016 16:43 12,844 iso8859_7.py 16-05-2016 16:43 11,036 iso8859_8.py 16-05-2016 16:43 13,156 iso8859_9.py 16-05-2016 16:43 1,023 johab.py 16-05-2016 16:43 13,779 koi8_r.py 16-05-2016 16:43 13,193 koi8_t.py 16-05-2016 16:43 13,762 koi8_u.py 16-05-2016 16:43 13,723 kz1048.py 16-05-2016 16:43 1,264 latin_1.py 11-07-2019 13:57 0 listmyfolder.txt 16-05-2016 16:43 36,467 mac_arabic.py 16-05-2016 16:43 14,102 mac_centeuro.py 16-05-2016 16:43 13,633 mac_croatian.py 16-05-2016 16:43 13,454 mac_cyrillic.py 16-05-2016 16:43 15,170 mac_farsi.py 16-05-2016 16:43 13,721 mac_greek.py 16-05-2016 16:43 13,498 mac_iceland.py 16-05-2016 16:43 14,118 mac_latin2.py 16-05-2016 16:43 13,480 mac_roman.py 16-05-2016 16:43 13,661 mac_romanian.py 16-05-2016 16:43 13,513 mac_turkish.py 16-05-2016 16:43 1,211 mbcs.py 07-09-2016 16:50 1,019 oem.py 16-05-2016 16:43 13,519 palmos.py 16-05-2016 16:43 14,015 ptcp154.py 16-05-2016 16:43 6,881 punycode.py 16-05-2016 16:43 1,525 quopri_codec.py 16-05-2016 16:43 1,208 raw_unicode_escape.py 16-05-2016 16:43 2,428 rot_13.py 16-05-2016 16:43 1,039 shift_jis.py 16-05-2016 16:43 1,059 shift_jisx0213.py 16-05-2016 16:43 1,059 shift_jis_2004.py 16-05-2016 16:43 12,300 tis_620.py 16-05-2016 16:43 1,299 undefined.py 16-05-2016 16:43 1,184 unicode_escape.py 16-05-2016 16:43 1,196 unicode_internal.py 14-06-2016 00:47 5,236 utf_16.py 16-05-2016 16:43 1,037 utf_16_be.py 16-05-2016 16:43 1,037 utf_16_le.py 14-06-2016 00:47 5,129 utf_32.py 16-05-2016 16:43 930 utf_32_be.py 16-05-2016 16:43 930 utf_32_le.py 16-05-2016 16:43 946 utf_7.py 16-05-2016 16:43 1,005 utf_8.py 16-05-2016 16:43 4,133 utf_8_sig.py 16-05-2016 16:43 2,721 uu_codec.py 16-05-2016 16:43 2,204 zlib_codec.py 11-09-2016 22:51 5,642 __init__.py 10-07-2019 18:27 <DIR> __pycache__ BR, Kazi RE: python -m venv VS virtualenv - Larz60+ - Jul-12-2019 I notice that when you're installing packages you're using both pip and pip3. Are you aware that pip and pip3 can be for two entirely different python versions? to check: pip -V which pip pip3 -V which pip3If they're not pointing to the same python, there's your problem. you need to be consistent in how you load packages use only one version of pip. also, a better way to list packages (with virtual environment activated) is to use: pip list RE: python -m venv VS virtualenv - kazi380 - Jul-15-2019 Hi Larz60, Thanks for pointing out your concern about my inconsistent us of the two Python Package managers (pip and pip3) Below are the outputs for the 'pip -V' and 'pip3 -V' commands with the virtual Python environment active. It seems both 'pip' and 'pip3' point to the same virtual environment, as expected. (myenv01) C:\myenv01\Scripts>pip -V pip 19.1.1 from c:\myenv01\lib\site-packages\pip (python 3.6) (myenv01) C:\myenv01\Scripts>pip3 -V pip 19.1.1 from c:\myenv01\lib\site-packages\pip (python 3.6) (myenv02) C:\myenv02\Scripts>pip -V pip 19.1.1 from c:\myenv02\lib\site-packages\pip (python 3.6) (myenv02) C:\myenv02\Scripts>pip3 -V pip 19.1.1 from c:\myenv02\lib\site-packages\pip (python 3.6) Anyway, at this moment I am still thinking that the issue is related to the differences between Python commands 'python -m venv' and 'virtualenv'. Especially because the critical files are already missing in 'myenv02' at that stage, before using the pip/pip3 commands to install the additional packages. I am becoming more convinced that the 'python -m venv' command doesn't install some of the standard Python modules/libraries which are needed to run a basic Python application. Most likely the Pyhton virual environment created with the 'python -m venv' command requires some reference to the standard Python modules/libraries located in the system Python(base pre-fix) to function properly. One more lead I forgot to mention in my initial post is the difference in output for two virtual environments when running the command 'mod_wsgi-express module-config'. (Note, this command generates some lines which are used for configuring the Apache24 server file 'httpd.conf' and tells Apache which Python interpreter to use when running the Python-Flask web-app) As you can see below, the Python virtual environment created with the python -m venv' command (myenv02) doesn't generate the 'Load file' line which seems to point to a basic Python library inside the system Python(base pre-fix). Unfortunate, manually adding the line to 'httpd.conf' doesn't resolve the issue. (myenv01) C:\myenv01\Scripts>mod_wsgi-express module-config LoadFile "c:/program files (x86)/microsoft visual studio/shared/python36_64/python36.dll" LoadModule wsgi_module "c:/myenv01/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd" WSGIPythonHome "c:/myenv01" (myenv02) C:\myenv02\Scripts>mod_wsgi-express module-config LoadModule wsgi_module "c:/myenv02/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd" WSGIPythonHome "c:/myenv02" BR,Kazi RE: python -m venv VS virtualenv - Tchouanga - Jul-17-2019 hello, to you all a still new to the use of Django I just really want to know the use the flask library in Django RE: python -m venv VS virtualenv - Larz60+ - Jul-17-2019 Tchouanga - You are pirating someone eases thread. This is against Forum rules. To get an answer, start a fresh thread. |