Sorry if this is dumb but every piece of documentation i read doesn't ever seem to answer this question in a direct way. How do i properly use virtualenv so that I have a virtualenv i can call with workon?
When i do tutorials like "Effective Django" they use the virtualenv command on an empty folder, then activate it. That works, until tomorrow when I want to work on the app again at which point the virtualenv is gone. What do i do at this point, I've used mkvirtualenv before and that creates a "permanent" virtualenv i can call with "workon" but I don't understand how i would use mkvirtualenv on an existing project or if this is a good idea or not, as it stands i have a project I virtualenv yesterday that has a bin folder in it and I am not sure if I need to source it again or what. Ideally i want to just workon project and get to work.
When i do tutorials like "Effective Django" they use the virtualenv command on an empty folder, then activate it. That works, until tomorrow when I want to work on the app again at which point the virtualenv is gone.
I strongly doubt that this is the case, unless something is deleting your directories overnight. If that is the case, stop putting your code where it is being deleted.
Assuming that is not the case, the solution is for you to go back to the directory you created as a virtualenv, and reactivate it.
Related
I have created a virtual environment with pyenv virtualenv 3.5.9 projectname for developing a django project.
How can I set environment variables for my code to use?
I tried to add the environment variable DATABASE_USER in /Users/developer/.pyenv/versions/projectname/bin/activate
like this:
export DATABASE_USER="dbuser"
When I tried to echo $DATABASE_USER an empty string gets printed.
Tried to install zsh-autoenv
And now I can echo $DATABASE_USER and get the value set in the .autoenv.zsh file.
But I can't seem to get the environment variable to be available to my django code:
If I try to os.getenv('DATABASE_USER', '') in the python shell inside the virtualenv, I get ''
What could be wrong? Is the zsh-autoenv variables just available for the zsh shell and not python manage.py shell ?
I was wondering a similar thing, and I stumbled across a reddit thread where someone else had asked the same question, and eventually followed up noting some interesting finds.
As you noticed, pyenv doesn't seem to actually use the bin/activate file. They didn't say what the activation method is, but like you, adding environment variables there yielded no results.
In the end, they wound up installing autoenv, which bills itself as directory-based environments. It allows you to create an .env file in your directory, and when you cd to that directory, it runs the .env file. You can use it for environment variables, or you could add anything else to it.
I noticed on the autoenv page that they say you should probably use direnv instead, as it has better features and is higher quality software. Neither of these are Python or pyenv specific, and if you call your python code from outside of the directory, they may not work. Since you're using pyenv, you're probably running your code from within the directory anyway, so I think there's a good chance either one could work.
I started working on my first python API hello world example on Friday on my VPS that is running Ubuntu 14.04. I used python3, created folder, virtualenv, activated it and then electricity went out and my connection broke.
I've left it there, and tried to continue where I stopped. Now, I can't find a way to "get into active" mode (to get that command-line view saying something like
(myprojectenv)user#host:~/myproject$
I've searched for "deactivate" somewhere in order to re-activate it again, but can't find anything such.
Any help understanding what is proper way of handling Virtualenv's is appreciated.
You have to activate you virtualenv again. In bash you have to source the activate file:
source myprojectenv/bin/activate
OK, if someone ends up in similar situation as I did.
Just "activate" your virtualenv again:
$source yourenv/bin/activate
That will re-activate it, and then you can "deactivate".
I dont know how to word this question but here is the essence of what is going on. I am attempting to run ipython in accordance with the instructions below but I will explain it by way of pip because i am more familiar with it.
In command line If i want to install something with pip i must first navigate to the folder it is located in and then run it e.g.
cd "C:\Python27\ArcGIS10.2\Scripts
pip install "ipython[notebook]"
This works fine, if I am in any other location it will not work. this is fine but I am now trying to run something like the below in a separate folder and I cannot do it. i dont want to clutter that scripts folder with all of that jazz so i would really like to run ipython outside of the root folder.
git clone https://github.com/donnemartin/interactive-coding-challenges.git
cd interactive-coding-challenges
ipython notebook
I hope thats clear, it is to me but that isnt saying much.
also that scripts folder is already in env. variables.
to further muddy the water it will work if i include the whole path like below but i would love to just type ipython instead of all of this jazz.
C:\Python27\ArcGIS10.2\Scripts\ipython.exe notebook
You mention, your path is set, but perhaps it was only applied it temporarily? Make sure you use setx to make a permanent change:
setx path "%path%;C:\Python27\ArcGIS10.2\Scripts\"
Now exit the terminal and start it again - you should be able to run ipython from any location
I sincerely apologize for the noobish dribble thats about to come out here:
Okay so I am following along with a youtube tutorial using terminal/django/komodo edit to make a simple website. This is my first time really using terminal, I am having issues. I have read up on the terminal and searched this site for my question but to no avail. Im hoping someone will take the time to answer this for me as it is most infuriating. This is my first time working with virtual env's as well.
So my question is, How do I uhmm, I suppose "save" my virtual env settings?
So I have set up a new virualenv. Downloaded django and started up my server so I can see things such as the admin page, log in page, from the internet page. Things go as they should along with the tutorial until it comes time to eventually turn off my computer.
When I reload the virtualenv I cannot run the server, it gives me: Import error, no module named django.core.management.
I use pip freeze and it shows that django is no longer installed.
If trying to reinstall django it gives a long block of error messages.
All the work done within the virtualenv file is still visible for the komodo edit pages however, but it seems the terminal does not want to work properly. My only option thus far has been to completely remake a virualenv, re-set it all up with the proper imports, files, django and restart the project.
so my questions are:
how do I save my terminal and/or virtualenv settings?
What do I need to do before logging off to ensure I will be able to continue with my project?
Lets say I am going to continue with my project, How do I start up the project again via terminal? Is that where I am going wrong? I've assumed up until now that I must go into terminal, start the server again and then from komodo edit continue with my project, but inside the terminal everything goes wrong.
Im not even explicitly saying I cannot continue with my project, I am more saying the terminal is not recognizing I had django installed within my virtualenv, and it is not letting me start the server again.
I have tried doing the research on my own, I am not one to sit back and wait for an answer but being completely new, this is baffling. I am sorry for the noob questions, feel free to link another answered question or website that has the answer.
Thank you all!!
Let's start from the beginning:
You are in your project folder eg /home/me/myproject
You create a new virtualenv, eg virtualenv /home/me/virtualenvs/myprojectenv
You activate the new virtualenv:
source /home/me/virtualenvs/myprojectenv/bin/activate
...this means that python and pip commands now point to the versions installed in your virtualenv
You install your project dependencies pip install django
You can ./manage.py runserver successfully
Now, the virtualenv has only been activated in your current terminal session. If you cd outside your project directory the virtualenv is still active. But if you open a new terminal window (or turn off the computer and come back later) the virtualenv is not activated.
If the virtualenv is not activated then the python and pip commands point to the system-installed copies (if they exist) and Django has not been installed there.
All you need to do when you open a new terminal is step 3. above:
source /home/me/virtualenvs/myprojectenv/bin/activate
Possibly the tutorial you followed got you to install virtualenvwrapper which is an additional convenience layer around the virtualenv commands above. In that case the steps would look like this:
You are in your project folder eg /home/me/myproject
You create a new virtualenv, eg mkvirtualenv myprojectenv
...virtualenv has already been activated for you now!
You install your project dependencies pip install django
You can ./manage.py runserver successfully
and whenever you start a new shell session you need to:
workon myprojectenv
in order to re-activate the virtualenv
I'm working with pycharm 3 pro on windows. I'm trying to set up a virtualenv to develop django in.
I have my virualenv in /f/development3/tools/virtualenvs/. Its called "renv". I have a project in /f/PycharmProjects/ called "r1".
In pycharm I have set the interpreter to r1 to be the virtualenv "renv". However when I open a terminal and do:
/f/PycharmProjects/r1 $ which pip
/f/Python27/Scripts/pip
So it seems that the project is not assosciated with the virtualenv through pycharm. Rather than try to figure out how to do this in pycharm ( I've posted a question in their forum ) I would like to put my django project "into" the virtualenv using the command line ( or cutting/pasting ). How do I do this?
Well you would need to associate your project with the virtualenv assuming that have created a virtualenv in the first place. Then you would need to use virtualenvwrapper and then use the workon command. This is actually more involved than you'd initially expect.
I could give you a long explanation regarding this, but there is already an excellent tutorial regarding this. virtualenv and virtualenvwrapper
Please note that virtualenvwrapper is *nix specific, so for windows you would need to find an alternate solution. Luckily such a solution exists, and its for powershell.
Actually, there is a port of virtualenvwrapper for Windows, called virtualenvwrapper-win. It works specifically on the Windows command line (not powershell). You may, of course, prefer to work in powershell,
but be aware of what your options are. The only drawback is that you need to do your git adds/commits, etc. in a separate git bash shell.