OError: [Errno 26] Text file busy: '/...myvirtualenv/bin/python'

guettli picture guettli · Nov 3, 2016 · Viewed 18.6k times · Source

I try to recreate the virtualenv:

foo_bar_d@aptguettler:~$ virtualenv --system-site-packages . 

I get this exception:

foo_bar_d@aptguettler:~$ virtualenv --system-site-packages .
New python executable in /home/foo_bar_d/bin/python
Traceback (most recent call last):
  File "/usr/local/bin/virtualenv", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 711, in main
    symlink=options.symlink)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 924, in create_environment
    site_packages=site_packages, clear=clear, symlink=symlink))
  File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 1230, in install_python
    shutil.copyfile(executable, py_executable)
  File "/usr/lib/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 26] Text file busy: '/home/foo_bar_d/bin/python'

Does someone know why this exception happens?

Answer

lbt picture lbt · Nov 10, 2016

I had the exact same problem :)

virtualenv works (afaik) by modifying a copy of the python executable in the virtualenv directory area.

You must have a process using the virtualenv already so the copy of the python executable is 'in use' (technically it's mmap()'ed into memory whilst it's executing).

Unless you need to change the setup of a virtualenv you don't need to re-run the virtualenv command every time - once it's setup you just activate it when needed.

As to why it happens - It's possible that you have a service running at boot time:

ps -ef | grep python