[Python] New Relic Admin not working on Python 3.10 Virtual Environment

When running newrelic-admin run-program I am running into the agent not finding activate_this.py. This is because in the virtualenv bin directory, activate_this.py no longer exists on Python 3.10.4

  • APM Agent Language: Python
  • APM Agent Version:
  • Operating System: CentOS
  • Operating System Version: 7
  • Frameworks your app is using: Flask, Gunicorn

Service Command

/srv/redacted/venv/bin/newrelic-admin run-program /srv/redacted/venv/bin/gunicorn -w 4 -b :8001 -t 1800 api:app

Stack Trace

May 24 02:25:40 ip-redacted redacted: Traceback (most recent call last):
May 24 02:25:40 ip-redacted redacted: File "/srv/redacted/venv/bin/newrelic-admin", line 3, in <module>
May 24 02:25:40 ip-redacted redacted: import os; activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); exec(compile(open(activate_this).read(), activate_this, 'exec'), { '__file__': activate_this}); del os, activate_this
May 24 02:25:40 ip-redacted redacted: FileNotFoundError: [Errno 2] No such file or directory: '/srv/redacted/venv/bin/activate_this.py'
May 24 02:25:40 ip-redacted systemd: redacted.service: main process exited, code=exited, status=1/FAILURE
May 24 02:25:40 ip-redacted systemd: Unit redacted.service entered failed state.
May 24 02:25:40 ip-redacted systemd: redacted.service failed.

Hi @mmora

Thanks for reaching out! I hope you are well great to see you posting again.

Please allow me to loop in the Python engineering team here as Python is out of my scope unfortunately.

Please note the engineer will reach out via this post with any updates. Should you have any additional questions or updates please do reach out!

Hey @mmora,

I reviewed this with our engineers, and on a fresh install of 3.10.4 we were unable to replicate the issue, both with a simple python script or with gunicorn+flask. We suspect it could be a problem with the virtualenv being used; it might need to be recreated or the package might need to be updated.

It looks like you are using the package virtualenv rather than the built in python -m venv to create your environment, and that’s likely the source of the issue. However, there doesn’t appear to be anything inherently wrong with virtualenv as it works fine with the agent and flask+gunicorn in our test environment.

We would recommend to:

  • Remove the existing virtual environment completely with an rm -rf
  • Either use the built-in python -m venv instead of virtualenv , or reinstall/update virtualenv to the newest version
  • Create the virtual environment again from scratch
  • Install the agent and other dependencies again
  • Test first with just gunicorn and not the agent to see if there’s an underlying issue with the virtualenv before trying to use the agent.

I hope this helps!