19

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?

guettli
  • 25,042
  • 81
  • 346
  • 663
  • Reboot your computer , probably got a ghost application. Or this file owner not system_default_user. – dsgdfg Nov 03 '16 at 14:19
  • @dsgdfg it was the same after rebooting my computer. File ownership is ok, I checked it twice. – guettli Nov 03 '16 at 15:52
  • Package updater use python and python configuration files is under lock. Stop every python process and use `bash` for replace/delete/change virtual env file. Or use your changes as a `Package`. – dsgdfg Nov 09 '16 at 08:09
  • @dsgdfg can you please explain what you mean with "Or use your changes as a Package". I don't understand your hint. – guettli Nov 09 '16 at 08:46
  • `OS` manage your all env. You want change/add your default python-env but can't change with using `python`. Create a `BASH` script, make some changes and save. Package is OS package not python-package. ONUSE, ONBUSY, ONLOCK can't change if source and target are same ! – dsgdfg Nov 09 '16 at 09:10
  • @dsgdfg yes, I understood that some process is still blocking the file. I am unsure if I need to use a bash script. I guess there is a server which uses this file ... yes, that's the case. I can recreate the virtualenv after stopping the server. If you write your comment as answer, I will upvote it. – guettli Nov 09 '16 at 10:56

2 Answers2

28

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
lbt
  • 766
  • 6
  • 10
  • Yes, I know that I don't need to re-run the virtualenv command. I updated my laptop from ubuntu-14 to ubuntu-16. After this made the re-run necessary. – guettli Nov 10 '16 at 15:34
  • 1
    real life example may be in another ssh session opened django shell causing such error when bootstraping with fabric... – andilabs Jan 11 '18 at 22:55
1

Kill Python Processes running on your system with pkill python

I will work

SAKhan
  • 249
  • 4
  • 16