Forums

Virtualenv not working suddenly

Hello,

I created a virtualenv just yesterday without any issues, and now I am getting thsi when I try to create a new one.

/usr/local/bin/virtualenvwrapper.sh: line 230: : command not foundvirtualenvwrapper.sh: There was a problem running the initialization hooks.

If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON= and that PATH is
set properly.
23:59 ~$

Did you modify your ~/.bashrc file? How does it look now?

No modifications were made. Here is how it currently looks :)

22:11 ~$ cat .bashrc
# Load up standard site-wide settings.
source virtualenvwrapper.sh
source /etc/bashrc

That is a very truncated .bashrc. Delete it and then start new consoles until it re-appears. That will be the default .bashrc and then in a new console, virtualenvwrapper shoudl work again.

I recreated .bashrc and now it looks like this:

    23:17 ~ $ cat .bashrc
# Load up standard site-wide settings.
source /etc/bashrc
#remove duplicate entries from history
export HISTCONTROL=ignoreboth
# Show current git branch in prompt.
function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
LIGHT_GREEN="\[\033[1;32m\]"
RESET_COLOR="\[\033[0;0m\]"
PS1="$RESET_COLOR\$(date +%H:%M) \w$YELLOW \$(parse_git_branch)$LIGHT_GREEN\$ $RESET_COLOR"
# Load virtualenvwrapper
source virtualenvwrapper.sh &> /dev/null

here is the error :

mkvirtualenv --python /usr/bin/python3.9 projectname
AttributeError: module 'virtualenv.create.via_global_ref.builtin.cpython.mac_os' has no attribute 'CPython2macOsFramework'

Is this in a new console after you changed the .bashrc?

Yep! I closed all my consoles and this Is the result. I tried deleting the partially created virtualenv folder in .virtualenvs and starting over, as well as with a different project name. Same problem

Yeah weird. I search around for the error and found this . It might be a package that you have installed in your base env that you need to uninstall

Is there a way to get a list of the standard packages so I can see what needs to be potentially be uninstalled?

The article suggests there are two versions of virtualenv installed and that is what caused his error, but I can't unisntall virtualenv due to rights.

    ERROR: Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/shutil.py", line 806, in move
    os.rename(src, real_dst)
OSError: [Errno 18] Invalid cross-device link: '/usr/local/lib/python3.9/site-packages/virtualenv-20.4.7.dist-info/' -> '/tmp/pip-uninstall-_kqpoh02'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 180, in _main
    status = self.run(options, args)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/commands/uninstall.py", line 85, in run
    uninstall_pathset = req.uninstall(
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/req/req_install.py", line 672, in uninstall
    uninstalled_pathset.remove(auto_confirm, verbose)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/req/req_uninstall.py", line 386, in remove
    moved.stash(path)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/req/req_uninstall.py", line 275, in stash
    renames(path, new_path)
  File "/usr/local/lib/python3.9/site-packages/pip/_internal/utils/misc.py", line 324, in renames
    shutil.move(old, new)
  File "/usr/local/lib/python3.9/shutil.py", line 824, in move
    rmtree(src)
  File "/usr/local/lib/python3.9/shutil.py", line 718, in rmtree
    _rmtree_safe_fd(fd, path, onerror)
  File "/usr/local/lib/python3.9/shutil.py", line 675, in _rmtree_safe_fd
    onerror(os.unlink, fullname, sys.exc_info())
  File "/usr/local/lib/python3.9/shutil.py", line 673, in _rmtree_safe_fd
    os.unlink(entry.name, dir_fd=topfd)
PermissionError: [Errno 13] Permission denied: 'zip-safe'

You will find pre-installed packages here.

Alrighty, getting closer.. I think? I tried removing the last two packages I installed which didn't help. I did find that It is only broken for python 3.9. Is there anyway to reset 3.9's image somehow?

20:58 ~ $ mkvirtualenv --python /usr/bin/python3.9 projectname
RuntimeError: failed to build image pip because:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/virtualenv/seed/embed/via_app_data/via_app_data.py", line 57, in _install
    installer.install(creator.interpreter.version_info)
  File "/usr/local/lib/python3.9/site-packages/virtualenv/seed/embed/via_app_data/pip_install/base.py", line 46, in insta
ll
    for name, module in self._console_scripts.items():
  File "/usr/local/lib/python3.9/site-packages/virtualenv/seed/embed/via_app_data/pip_install/base.py", line 131, in _con
sole_scripts
    entry_points = self._dist_info / "entry_points.txt"
  File "/usr/local/lib/python3.9/site-packages/virtualenv/seed/embed/via_app_data/pip_install/base.py", line 118, in _dis
t_info
    raise RuntimeError(msg)  # pragma: no cover
RuntimeError: no .dist-info at /home/MorePyPlease/.local/share/virtualenv/wheel/3.9/image/1/CopyPipInstall/pip-23.2.1-py3
-none-any, has pip
20:58 ~ $ mkvirtualenv --python /usr/bin/python3.8 projectname
created virtual environment CPython3.8.5.final.0-64 in 9275ms
  creator CPython3Posix(dest=/home/MorePyPlease/.virtualenvs/projectname, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/MorePyPlea
se/.local/share/virtualenv)
    added seed packages: pip==21.1.2, setuptools==57.0.0, wheel==0.36.2
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
virtualenvwrapper.user_scripts creating /home/MorePyPlease/.virtualenvs/projectname/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/MorePyPlease/.virtualenvs/projectname/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/MorePyPlease/.virtualenvs/projectname/bin/preactivate
virtualenvwrapper.user_scripts creating /home/MorePyPlease/.virtualenvs/projectname/bin/postactivate
virtualenvwrapper.user_scripts creating /home/MorePyPlease/.virtualenvs/projectname/bin/get_env_details
(projectname) 21:00 ~ $ deactivate
21:38 ~ $ rmvirtualenv projectname
Removing projectname...
21:38 ~ $ virtualenv list
RuntimeError: failed to build image pip because:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/virtualenv/seed/embed/via_app_data/via_app_data.py", line 57, in _install
    installer.install(creator.interpreter.version_info)
  File "/usr/local/lib/python3.9/site-packages/virtualenv/seed/embed/via_app_data/pip_install/base.py", line 46, in install
    for name, module in self._console_scripts.items():
  File "/usr/local/lib/python3.9/site-packages/virtualenv/seed/embed/via_app_data/pip_install/base.py", line 131, in _console_scripts
    entry_points = self._dist_info / "entry_points.txt"
  File "/usr/local/lib/python3.9/site-packages/virtualenv/seed/embed/via_app_data/pip_install/base.py", line 118, in _dist_info
    raise RuntimeError(msg)  # pragma: no cover
RuntimeError: no .dist-info at /home/MorePyPlease/.local/share/virtualenv/wheel/3.9/image/1/CopyPipInstall/pip-23.2.1-py3-none-any, has pip

This bug article seems to be the crux of the situation: https://github.com/pypa/virtualenv/issues/2565

Somehow I may have duplicated this inside of my environment? https://github.com/pypa/virtualenv/issues/2565#issuecomment-1614765476

Is there a way to fix this with more permission than I have?

I Found this other reference and deleted my wheel directories and it appears to be working now. You might consider adding this to the KB.

https://www.pythonanywhere.com/forums/topic/30846/

22:09 ~/.local/share/virtualenv/wheel $ rm -rf 3.9 22:09 ~/.local/share/virtualenv/wheel $ dir 3.8 house 22:09 ~/.local/share/virtualenv/wheel $ rm -rf 3.8 22:09 ~/.local/share/virtualenv/wheel $ cd /

Thanks for the update!