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

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?

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

Kill Python Processes running on your system with pkill python
I will work

Related

creating a virtualenv gives a permission denied

I'm trying to create a virtualenv, but I'm getting a Permission denied error. I'm using the following code
python2.7 -m virtualenv -p `which python2.7` test
Which gives this error message:
--edit--
I get a permission denied error
Traceback (most recent call last):
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_set.py", line 784, in install
**kwargs
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/wheel.py", line 287, in clobber
ensure_dir(dest) # common for the 'include' path
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv_support/pip-9.0.1-py2.py3-none-any.whl/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/home/marco/development/openplus/lambda/resizeTestSam/test/lib/python2.7/os.py", line 152, in makedirs
makedirs(head, mode)
File "/home/marco/development/openplus/lambda/resizeTestSam/test/lib/python2.7/os.py", line 159, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/lib/python2.7'
and a final error the operation failed
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 2328, in <module>
main()
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 713, in main
symlink=options.symlink)
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 945, in create_environment
download=download,
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 901, in install_wheel
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
File "/home/marco/.local/lib/python2.7/site-packages/virtualenv.py", line 797, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /home/marco/developm...m/test/bin/python2.7 - setuptools pip wheel failed with error code 2
To debug the error in os.py, I've added a print statement, it looks like the script tries to make the directories /lib/python2.7 and /lib/python2.7/site-packages. I don't understand why virtualenv tries to create these directories there and not in my current directory.
I've installed virtualenv without sudo, so I don't expect it to create directories in a path that is owned by root.
In the end only the python executable is copied to the 'test' directory, but not setuptools, pip and wheels.
Is there a way to avoid virtualenv from accessing root owned directories?
--update--
using python3 with venv works fine, the problem is with virtualenv specifically.
Executing virtualenv from my home directory give no error.
Looks like you're trying to create the virtualenv test within /lib/python2.7/site-packages, which, by all rights, you shouldn't have write access to.
Try running cd ~ first, to create the venv in your home directory.
I had the same mysterious error; it turns out I had forgotten a setting in my $HOME/.pip/pip.conf that changed the prefix.

virtualenv hanging forever pythonanywhere

I am trying to follow this tutorial to get a django application up on pythonanywhere, but when trying to create a virtual environment using
virtualenv --python=python3.5 myvenv
The console hangs
I have done this before a while ago and I remember it was all quite painless but when running this command the console is just hanging and I eventually get put in the tarpit. When I interrupt the process I get some errors around Python 2.7
virtualenv --python=python3.5 myvenv
Running virtualenv with interpreter /usr/bin/python3.5
Using base prefix '/usr'
New python executable in /home/username/myvenv/bin/python3.5
Also creating executable in /home/username/myvenv/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 669, in main
Traceback (most recent call last):
raise SystemExit(popen.wait())
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 2327, in <module>
File "/usr/lib/python2.7/subprocess.py", line 1376, in wait
pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
File "/usr/lib/python2.7/subprocess.py", line 476, in _eintr_retry_call
return func(*args)
KeyboardInterrupt
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 944, in create_environment
download=download,
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 900, in install_wheel
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 767, in call_subprocess
line = stdout.readline()
KeyboardInterrupt
Not sure if these relate to anything or if they are just because the interrupt.
General practice is to reference the python binary directly, run virtualenv as a module, and specify the directory in which to place the virtualenv. For your example above:
/path/to/python/bin/python3.5 -m virtualenv myvenv
This will create the virtual environment in myvenv, running python3.5. Note: your base install of python3.5 must have virtualenv library installed (either through pip or source).
Hope this helps! :)

Virtualenv: can't create virtualenv: IOError: [Errno 2] No such file or directory: 'python'

This happens when attempting to update the python installation in my virtualenv OR when creating a new virtualenv:
[marcintustin#localhost oneclickrep]$ virtualenv --always-copy --clear --python=/usr/bin/python oneclickcosvirt/
Already using interpreter /usr/bin/python
Deleting tree oneclickcosvirt/lib/python2.7
Not deleting oneclickcosvirt/bin
New python executable in oneclickcosvirt/bin/python
Traceback (most recent call last):
File "/usr/bin/virtualenv", line 9, in <module>
load_entry_point('virtualenv==1.10.1', 'console_scripts', 'virtualenv')()
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 821, in main
symlink=options.symlink)
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 956, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 1377, in install_python
shutil.copyfile(py_executable_base, full_pth)
File "/usr/lib/python2.7/shutil.py", line 82, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: 'python'
[marcintustin#localhost oneclickrep]$
The result is consistently the above. /usr/bin/python exists and is working very nicely (it's also the python picked up by which). What's the cause here?
Edit: Using virtualenv version 1.10.1
This is a bug with virtualenv. Using the --always-copy flag triggers copying behaviour, which is broken. There are bug reports and patches already submitted.
The line shutil.copyfile(py_executable_base, full_pth) should be shutil.copyfile(py_executable, full_pth).

python can't use virtualenv

i'm running Python 2.7 with my debian testing and i've a probleme using virtualenv.
Im trying to create a virtualenv on a partition which is mount like
/dev/sda5 /media/misc vfat users,defaults,uid=1000,gid=1000,exec,umask=0 0 0
So, rights seems ok but virtualenv returns me :
Traceback (most recent call last):
File "/usr/bin/virtualenv", line 3, in <module>
virtualenv.main()
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 938, in main
never_download=options.never_download)
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 1039, in create_environment
site_packages=site_packages, clear=clear))
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 1186, in install_python
copyfile(join(stdlib_dir, fn), join(lib_dir, fn))
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 430, in copyfile
copyfileordir(src, dest)
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 405, in copyfileordir
shutil.copytree(src, dest, True)
File "/usr/lib/python2.7/shutil.py", line 206, in copytree
raise Error, errors
shutil.Error: [('/usr/lib/python2.7/config/libpython2.7.so', 'seb/lib/python2.7/config /libpython2.7.so', '[Errno 1] Operation not permitted')]
i've installed virtualenv with apt.
using virtualenv in my /home is successfull
can you help me ?
fixed. I don't exactly why, but i've formated my partiton with a ntfs type resolves the issue.
It seems that fat32 system adds control over fstab

Unable to do heroku's Python tutorial within Dropbox folder

EDIT2: OK this is weird. (I can't answer my own question, so I just put it as another edit to the question. I think it has something to do with the fact that I tried to do this installation within a Dropbox-synced directory. I got this to work on my Desktop. Can anyone explain why this is the case?
Original question:
I'm trying to do Heroku's Python setup tutorial (http://devcenter.heroku.com/articles/python), on my Mac OS X (Lion), but I get caught up with the step of creating a virtualenv.
So what I did was this in the command line (not using sudo caused permissions error):
sudo pip install virtualenv
But then, when I do "virtualenv venv --distribute" (I also tried with sudo), I get the following error:
New python executable in venv/bin/python
Installing distribute..............................................................................................................................................................................................................................................................................................done.
Installing pip...
Error [Errno 2] No such file or directory while executing command /Users/AndyFang/Drop...env/bin/easy_install /Library/Python/2.7/...pport/pip-1.1.tar.gz
...Installing pip...done.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 8, in <module>
load_entry_point('virtualenv==1.7.1.2', 'console_scripts', 'virtualenv')()
File "/Library/Python/2.7/site-packages/virtualenv.py", line 928, in main
never_download=options.never_download)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 1042, in create_environment
install_pip(py_executable, search_dirs=search_dirs, never_download=never_download)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 640, in install_pip
filter_stdout=_filter_setup)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 966, in call_subprocess
cwd=cwd, env=env)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Not really sure what to do. It seemed like I didn't have easy_install on my Mac, but I do have it... I'm not sure what the deal is?
EDIT: I also just tried installing virtualenv with easy_install, but I get the exact same error.
If your problem is the same as mine, then it's because there's a space somewhere in the path to your Dropbox-synced folder.
Virtualenvs aren't portable, so you can't keep them synced across multiple machines if the paths don't match up.
In general, it's a bad idea :)

Categories