0

I am trying to get a virtual environment for Django development but I cannot get it working.

So far I have:

sudo pip3 install virtualenvwrapper

I have then added the following to /home/pi/.bashrc

export WORKON_HOME=$HOME/.virtualenvs

export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3

export VIRTUALENVWRAPPER_VIRTUALENV_ARGS=' -p /usr/bin/python3 '

export PROJECT_HOME=$HOME/Devel

source /usr/local/bin/virtualenvwrapper.sh

I then reload the startup file:

source ~/.bashrc

And finally I run:

mkvirtualenv my_django_environment

Which outputs the following:

created virtual environment CPython3.7.3.final.0-32 in 460ms creator CPython3Posix(dest=/home/pi/.virtualenvs/my_django_environment, clear=False, global=False) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/pi/.local/share/virtualenv) added seed packages: pip==20.2.2, setuptools==49.6.0, wheel==0.35.1 activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator virtualenvwrapper.user_scripts creating /home/pi/.virtualenvs/my_django_environment/usr/local/bin/predeactivate ERROR: Environment '/home/pi/.virtualenvs/my_django_environment' does not contain an activate script.

I'm guessing that this is my problem:

ERROR: Environment '/home/pi/.virtualenvs/my_django_environment' does not contain an activate script.

I've not found any recourse online, only these ERROR: Environment '/home/pi/.virtualenvs/cv' does not contain an activate script & https://stackoverflow.com/questions/60252119/error-environment-users-myuser-virtualenvs-iron-does-not-contain-activation-s/60292344#60292344

Neither of which solve my error. Any ideas?

  • 2
    Although you do not say why you are using .bashrc for this, 99% (without exaggeration) of the uses I've seen here are based on the completely erroneous assumption that bashrc is supposed to run at boot to start stuff. Wrong-o. It may run at boot, but that is not because it is supposed to, and there are a lot of other times that are not boot that it may also run. If you too don't know when it is truly supposed to run, why are you using it? All apologies if you do know, and this is on purpose, of course ;) – goldilocks Sep 21 '20 at 13:58
  • I've been using Ubuntu for two months so I genuinely didn't know. However the guide I followed was from Mozilla: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/development_environment - I wouldn't follow just any old guide but I thought something from Mozilla would be OK. – norfolk_uk Sep 21 '20 at 19:13

2 Answers2

1

It is unclear what you are trying to do BUT one thing is clear:-
.bashrc is NOT intended to run scripts.

It is run each time a non-login interactive shell is started and is used to configure the shell.
~/.bashrc: executed by bash(1) for non-login shells.

Milliways
  • 59,890
  • 31
  • 101
  • 209
  • .bashrc is not intended to run scripts? OK, but a lot of guides recommend placing them there. Is there a reason that it is a bad idea? – norfolk_uk Sep 21 '20 at 13:40
  • 2
    That probably isn't the cause of the problem, but Milliways is correct in pointing this out and it is because there are so many "guides" out there that recommend this based on the "guide" author's total ignorance of the mechanism and the fact that he/she has just copy pasted it from someone else who did not know what they are doing. Unfortunately, we can't downvote or correct I-gots-a-wordpress-account "guides" and so when people see easy (and so many others have pointed out the earth is flat! must be so!) and no critics they think, "Good O!" – goldilocks Sep 21 '20 at 13:54
  • I see, well I'm fairly new to Linux so I didn't know. Although the guide I followed was from Mozilla itself... https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/development_environment Is it a by design no-no or are the other more serious reasons for not doing that? – norfolk_uk Sep 21 '20 at 19:10
0

It seems I was missing a line...

And I fixed it by placing the following in /home/pi/.bashrc:

export VIRTUALENVWRAPPER_ENV_BIN_DIR=bin

And then reloading again:

source ~/.bashrc

This then gave me access to commands such as workon etc..

HOWEVER - I have been advised that putting such stuff in .bashrc to get stuff to run at start up is not what .bashrc is for. But I'm new to Linux so I don't know. But what I did, achieved what I was trying to do, rightly or wrongly..

  • If you are running a Pi as a standalone computer, with a monitor, keyboard and mouse, then running scripts from your home .bashrc may be kind of OK, but if you run it headless, like many people do, those scripts will be run every single time you log in remotely using ssh, which may not be convenient. – Michael Harvey Sep 23 '20 at 10:12