Title: venv base path does not resolve symlinks using realpath() · Issue #106045 · python/cpython · GitHub
Open Graph Title: venv base path does not resolve symlinks using realpath() · Issue #106045 · python/cpython
X Title: venv base path does not resolve symlinks using realpath() · Issue #106045 · python/cpython
Description: It seems there is a bug in venv (and a similar one in virtualenv) where the "base" path in pyvenv.cfg is set incorrectly. If Python is installed in a non-standard folder, e.g. /usr/local/python-X.Y.Z and then symlinked into /usr/local/bi...
Open Graph Description: It seems there is a bug in venv (and a similar one in virtualenv) where the "base" path in pyvenv.cfg is set incorrectly. If Python is installed in a non-standard folder, e.g. /usr/local/python-X.Y...
X Description: It seems there is a bug in venv (and a similar one in virtualenv) where the "base" path in pyvenv.cfg is set incorrectly. If Python is installed in a non-standard folder, e.g. /usr/local/...
Opengraph URL: https://github.com/python/cpython/issues/106045
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"venv base path does not resolve symlinks using realpath()","articleBody":"It seems there is a bug in venv (and a similar one in virtualenv) where the \"base\" path in pyvenv.cfg is set incorrectly. If Python is installed in a non-standard folder, e.g. /usr/local/python-X.Y.Z and then symlinked into /usr/local/bin/python3, the venv package does not work correctly. I believe the source of the trouble is the setting of \"home\" variable. Specifically, this line:\r\n```\r\ndirname, exename = os.path.split(os.path.abspath(executable))\r\n```\r\nThe `dirname` result is used to set \"home\". If the executable path is /usr/local/bin/python3 (actually a symlink to /usr/local/python-X.Y.Z/bin/python3), the \"home\" should not be set to /usr/local. Changing the above line (in the `ensure_directories()`) function to:\r\n```\r\ndirname, exename = os.path.split(os.path.realpath(executable))\r\n```\r\nThis fixes the problem. I believe this is consistent with what the getpath.py module in Python does.\r\n\r\nI noticed with problem when running the most recent Debian OS, version 12. It includes Python 3.11 and therefore /usr/lib/python3.11 exists. With the above bug, the venv tries to use /usr/lib/python3.11 as the sys.path. Importing the `struct` module fails with the mysterious error:\r\n```\r\n\u003e\u003e\u003e import struct\r\nTraceback (most recent call last):\r\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\n File \"/usr/lib/python3.11/struct.py\", line 13, in \u003cmodule\u003e\r\n from _struct import *\r\nModuleNotFoundError: No module named '_struct'\r\n```\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-115237\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/nascheme","@type":"Person","name":"nascheme"},"datePublished":"2023-06-23T18:25:34.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":25},"url":"https://github.com/106045/cpython/issues/106045"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c6cbe1c1-558f-8b7a-addb-8e954ffa1d7b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DBA0:B5AA6:7E8C65:AA6F34:6A4EC51E |
| html-safe-nonce | 3df132b5533e907ef1a8015ff4159d055009c1dd6041b2064326d104e94b5a75 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQkEwOkI1QUE2OjdFOEM2NTpBQTZGMzQ6NkE0RUM1MUUiLCJ2aXNpdG9yX2lkIjoiOTE1NTYzOTQ0MTE3OTc4Mzk4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b7a466a8e096c62ad547bd3a178d451a6608cdca8bf12ff1fc261372af6f96cb |
| hovercard-subject-tag | issue:1771900453 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/106045/issue_layout |
| twitter:image | https://opengraph.githubassets.com/88bd16ccac0be710ffba8650ebd68227caabd0dd90a3137c6e04a6b131ad8ff0/python/cpython/issues/106045 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/88bd16ccac0be710ffba8650ebd68227caabd0dd90a3137c6e04a6b131ad8ff0/python/cpython/issues/106045 |
| og:image:alt | It seems there is a bug in venv (and a similar one in virtualenv) where the "base" path in pyvenv.cfg is set incorrectly. If Python is installed in a non-standard folder, e.g. /usr/local/python-X.Y... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nascheme |
| hostname | github.com |
| expected-hostname | github.com |
| None | 41b6ab3ba6d20a71766ac245b5a4a94c6fc672a9cd4da7d44c1b33ab8bf6a21c |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e6a744804e8e70f97b4d5a18a94dcc63db22f97a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width