I have two python environments and somehow there is some kind of link between them.
/home/testapi/API25/env is the original venv /home/preprodapi/API25/env was created by means of a cpio copy from the first. This worked find for many months. But now a problem has cropped up.
The symptom is that in preprodapi the pytz package isnt able to find the timezone Africa/Johannesburg (and presumably others), as evidenced by the stack trace:
Traceback (most recent call last): File "/home/preprodapi/API25.8512/validator/echo.py", line 244, in jsonified_wrapper response_obj = request_handler(*args, **kwargs) File "/home/preprodapi/API25.8512/validator/echo.py", line 478, in bearer_token_wrapper return request_handler(*args, **kwargs) File "/home/preprodapi/API25.8512/validator/echo.py", line 1068, in globaldb_connection_wrapper return request_handler(*args, **kwargs) File "/home/preprodapi/API25.8512/validator/echo.py", line 569, in get_school_wrapper return request_handler(*args, **kwargs) File "/home/preprodapi/API25.8512/validator/echo.py", line 697, in school_admin_wrapper return request_handler(*args, **kwargs) File "/home/preprodapi/API25.8512/routehandlers.py", line 4035, in email_report do_email_report(kwargs.get('reportid'), json_attrs, getctx_school().get('schoolname')) File "/home/preprodapi/API25.8512/validator/echo.py", line 1155, in do_email_report tz = pytz.timezone(sender.school.get("local_timezone")) File "/home/testapi/API25/env/lib64/python3.5/site-packages/pytz/__init__.py", line 181, in timezone pytz.exceptions.UnknownTimeZoneError: 'Africa/Johannesburg' Notice how it switches from /home/preprodapi/.... to /home/testapi/... in the final item.
But WHY is this happening?
(env) [root@ip-172-31-8-200 API25]# deactivate [root@ip-172-31-8-200 API25]# pwd /home/preprodapi/API25 [root@ip-172-31-8-200 API25]# . env/bin/activate (env) [root@ip-172-31-8-200 API25]# pip uninstall pytz Uninstalling pytz-2017.2: Would remove: /home/testapi/API25/env/lib/python3.5/site-packages/pytz-2017.2.dist-info/* /home/testapi/API25/env/lib/python3.5/site-packages/pytz/* Proceed (y/n)? n (env) [root@ip-172-31-8-200 API25]# python Python 3.5.5 (default, Feb 6 2018, 10:57:32) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pytz >>> print(pytz.timezone('Africa/Johannesburg')) Africa/Johannesburg For the record I can't find any soft links between the venv's
(env) [root@ip-172-31-8-200 API25]# pwd /home/preprodapi/API25 (env) [root@ip-172-31-8-200 API25]# find env -type l -ls 40549590 0 lrwxrwxrwx 1 root root 3 Feb 4 12:54 env/lib64 -> lib 40549592 0 lrwxrwxrwx 1 root root 15 Feb 4 12:54 env/bin/python3.5m -> /bin/python3.5m 40549593 0 lrwxrwxrwx 1 root root 10 Feb 4 12:54 env/bin/python -> python3.5m 40549594 0 lrwxrwxrwx 1 root root 10 Feb 4 12:54 env/bin/python3 -> python3.5m Help please!
P.S note /home/preprodapi/API25.8512 is a cpio copy of /home/preprodapi/API25. I get the exact same results when I test in the API25.8512 sub-directory
Note #2: The same does not happen with another venv on this host
[root@ip-172-31-8-200 API25.8512]# cd /home/apiuser [root@ip-172-31-8-200 apiuser]# cd API25 [root@ip-172-31-8-200 API25]# . env/bin/activate (env) [root@ip-172-31-8-200 API25]# pip uninstall pytz Uninstalling pytz-2018.9: Would remove: /home/apiuser/API25/env/lib/python3.5/site-packages/pytz-2018.9.dist-info/* /home/apiuser/API25/env/lib/python3.5/site-packages/pytz/* Proceed (y/n)? n
cpiois an archiver, not a copy utility.venv, install some packages into it, then copy it?pytz.__file__after you "uninstalled"pytzfrom the current virtual env?sys.pathandPYTHONPATH? Are you sure you're inside the right venv when the first error happens?