Skip to content

Tachyon incompatibility with virtual environments on Windows is inconvenient for scripts with dependencies #149560

@pt1243

Description

@pt1243

Feature or enhancement

Proposal:

On Windows, profiling.sampling does not work when run from a virtual environment. Based on #148932 it appears that this is expected behaviour, which is why I am filing this as a feature request instead of a bug report. (Feel free to change the labels if a bug report is more appropriate.)

Profiling from the system Python (i.e. not a virtual environment) is fine for using with attach command, but my use case involves profiling short-duration scripts with the run command. Some of these scripts have dependencies installed into a local virtual environment. Running the script under profiling while also including the dependencies requires one of the following options:

  1. Installing the script dependencies into the system Python environment.
  2. Adding a .pth file to the system Python which adds the virtual environment site packages directory to sys.path.

Neither of these options are ideal. In the case of (1), it is tedious to remember to install packages before profiling. Additionally, should different scripts have incompatible dependencies, it is necessary to also uninstall the packages afterwards when switching between them. In the case of (2), this generally quicker to set up, but it introduces additional complexity and confusion relating to what packages are effectively installed. For example, pip list shows the packages in the virtual environment site packages directory added by the .pth file, while uv pip list shows the contents of the system site packages.

Forgetting to keep the system site packages in sync with the script dependencies will, at best, result in import errors. In the worst case, different versions of the same package in the virtual environment and system site packages could cause silent behavioural changes depending if the scipt is being profiled or not.

I am not familiar with the implementation of profiling.sampling, so I don't know if it is feasible to make profiling.sampling work from a virtual environment. If it is possible, this would be a significant improvement to the user experience.

If this is not possible, then at the least I would suggest that the platform requirements section of the documentation should be updated to note this limitation. Ideally the documentation would also then include a suggested workaround for profiling with script dependencies, which could be one of the options above or some other solution that I'm not aware of.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-profilingtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions