I have been working on Django project from few weeks and everytime I run the server, or make migrations or migrate all the packages are seperated from system directory to virtualenvironment.
I execute the below command to kickstart virtualenvironment
$source venv/bin/activate
What does 'source' signify in the above command ?
Long story short, it sets your path environment variables so it knows to check for installed packages in your virtual environment directory, so you don't have to do things like install them in a directory which you don't have (sudo) access.
i.e. you can do pip install without sudo and still have your python know where to find that package.
For more details on the source command itself, see this link
Related
I am trying to add pipenv in project interpreter in pycharm but it throws an error.
These are the step that I followed :
-1- First in the command prompt I installed pip install pipenv
-2- Go to the directory of my project in the command prompt and typed pipenv shell (This command will look for the pipenv environment and load it, otherwise if not existing will create a new one)
-3- To install the last successful environment recorded (all packages and dependencies) typed pipenv install --ignore-pipfile to install production environment
-4- In PyCharm File->Settings->Project: ProjectName->Project Interpreter click add
-5- select pipenv environment, pycharm automatically shows pipenv executable
-6- Press OK - What am I miising here?
I installed pipeline globally and on my project directory
Runing pipenv shell on project directory shows this
Shell for C:\Users\gh8001\.virtualenvs\churn_prediction-UB3VC30i already activated.
No action taken to avoid nested environments.
In step 3, once you used 'pipenv install --ignore-pipfile' you already created a virtual environment. You need to get pycharm to use this existing virtual environment (not create a new virtual env). So, in step 5, instead of selecting 'pipenv environment', which seeks to create a new virtual env (and which I find doesn't work well for specifying exact python versions well), do this instead:
select 'Virtualenv Environment' tab
then 'Existing Environment' button
then point to the interpreter you created in step 3. You can find this interpreter by using 'pipenv --venv' for the root env directory, and then add /bin/python to the end.
Select OK, and the new pipenv should be in use
I faced the same problem. I spend half a day and finally found that the problem is in the stage of installing python.
Just uncheck the Install launcher for all users(recommended)
This option saves some of the python files such as pipenv.exe in the root C:\Users\your_pc\AppData\Roaming\ and causes the problem.
Hope this works for you.
pipenv executable should point to a pipenv.exe file, not a python.exe file. I don't know why pycharm would incorrectly detect this.
I think you may install pipenv using pip in anaconda. So you can find you pipenv executable in your anaconda/bin directory.
I cloned a repo and I'm trying to run my tests and i'm getting an interpreter error:
Interpreter path does not exist: C:\Users\username\Source\Repos\citcodownloader\env\Scripts\python.exe
The project downloaded a .sln, solutions view that I opened it with and I thought it set up my enviornment but it doesn't seem to be doing so. Not sure what to do from here.
The best thing you can do is create a (or use an existing) Virtual Environment. It looks like your program is looking for one in the folder "env". Try this:
Open a terminal (Windows key + R, then type cmd and press enter)
Navigate to your repo folder using chdir C:\path\to\your\repo
Run the command env\Scripts\activate.bat (if there is no folder called "env" in your repo, use my instructions below)
Try running your program again.
I hope this helps, post a comment if it doesn't and I'll add as much detail or explanation as you need. Good luck!
For Googlers or people who that doesn't help, look for these files in your repo:
requirements.txt (a list of plugins you need to set up a virtual environment)
venv/ (folder containing a virtual environment)
Solution
If a folder named 'venv' or 'virtualenv' does NOT exist,
run this command to create it: python -m venv venv (or for Python 3: python3 -m venv venv). If it does exist, move forward.
You have a virtual environment! Now enter into it using: source venv/bin/active (on Unix or OSX, see the link above for the Windows command).
If requirements.txt is there, run this command next: pip install -r requirements.txt. If not, move forward.
Run the program again (via whatever method the repo says you should use). If you get 'error: module is not installed' use the command pip install moduleNameHere and run the program again.
Keep doing step 4 for each missing module, once the program is working use pip freeze > requirements.txt to create a requirements file and save yourself the headache next time. :)
I'm using Ubuntu 15.04 with Python 2.7, pip 1.5.6 and virtualenv 1.11.6.
I will create a Django project inside /var/www/html/project_name (and work in that directory) for use it with Apache2.
I created a virtual environment named venv inside the project_name folder for syncing purposes.
With the virtual environment activated, I just cant't run pip install django because I get 'Permission denied' message. So I try the command sudo pip install django, but that will install Django globally.
So, running which pip, I get /var/www/html/project_name/venv/bin/pip.
But running sudo which pip, I get /usr/bin/pip.
Does someone get any idea about how it is possible to install Django (or any other package) inside the virtual environment?
PS: I know it's possible to run sudo venv/bin/pip install django, but it doesn't seem very useful.
Your trouble is presumably that you don't have write access to this /var/www/html/project_name directory. Your choices are:
Change the permissions, recursively, so that you do have permissions to write to that directory.
Run the following commands:
.
$ sudo su
# . venv/bin/activate
# pip install
Just to add what everyone's been saying and I sort of skimmed over: NEVER EVER put sensitive things (that includes your django project) under the document root. You can store it under something like /var/www/scripts or something, but don't put it under the document root.
Another way of deploying is using something like gunicorn as the "main" webserver and then just having whatever world visible webserver (like apache) reverse proxy to gunicorn. I've done this with nginx and it's fairly easy to setup, the only down side is then you have to setup something extra in your system's init scripts to start up gunicorn.
I'm trying to build a simple API server using Flask that will validate and store international phone numbers using this phonenumbers.py. I previously installed Flask and several Flask extensions in a virtualenv, and started building my app. So far so good. But after downloading and installing phone numbers.py using its own installer, I found that python running inside virtualenv could no longer find my app script! Looking at the directory, it's sitting right there, but python does not recognize it any more. The only other wrinkle I can think of is that after doing the install, I used an external text editor (outside the venv) to edit my app script and re-save it.
What have I done wrong?
I compared my environment variables inside and outside virtualenv. They are the same except for the following 3 additions:
VIRTUAL_ENV=/Users/tokrum/callcenter/venv
PATH=/Users/tokrum/callcenter/venv/bin # (was added to the beginning of my $PATH, but the rest of pre-existing PATH is as beforeā¦.)
PS1=(venv)\h:\W \u\$
My app is called callcenter-v0-1.py. It lives in a directory called /callcenter/, along with the phone numbers-7.0.1 and venv folders at the same level of my directory structure.
Thanks for any light you can shed on this.
Install Flask_script in your virtual env using
$pip install Flask-Script
Make sure that you activated the virtualenv before you installed Flask and your other dependencies -
$ virtualenv env
$ source env/bin/activate
$ pip install flask
Then when you're done working, make sure to deactivate the environment -
$ deactivate
Finally, when you want to start working again, navigate to your project directory and reactivate the environment -
$ source env/bin/activate
At this point, I would just remove the virtualenv and start over.
Hope that helps!
I was given a project to work on and am now trying to run that project in a virtual environment.
I am new to python, but in the past, I was comfortable with the "manage.py runserver" concept. I'm having trouble learning virtual environments.
I know that I have virtualenv installed.
My first direction given to run the virtual environment for this project was to run virtualenv --python=/var/bin/python --clear --no-site-packages --unzip-setuptools --setuptools ~/virtualenvs/project_name
That results in this error:
The executable /var/bin/python (from --python=/var/bin/python) does not exist
I already have python installed, what does this even mean? I am also confused about this syntax, --python=/var/bin/python, was that a relative path that I should have switched out "python=/" for something else? what does the "=/" actually represent?
Am I running the command in the wrong folder? I have tried running it in both the outer project_name folder, containing a subfolder of the same name, and also, inside that subfolder (which contains the manage.py).
However, I can't find the var/bin/... paths anywhere in either folder. Where should the bin paths be located?
Any help or insights would be much appreciated, thanks!
If you are new to virtual environments, these are the steps I would take to install a virtual environment. I hope this helps.
Setuptools
First to check if you already have it installed type the following:
python
>>>import setuptools
If you get another >>> then you have it installed, otherwise you'll get an error. If you happen to blow up setuptools, here's how you reinstall it:
http://pypi.python.org/pypi/setuptools
1.Download Python 2.7 egg
2.Change directory into new unzipped folder
3.Run the following command:
sudo sh ~/folder/you/downloaded/to/setuptools-0.6c11-py2.7.egg
Virtialenvwrapper
sudo pip install virtualenvwrapper
Setup
1.Create your directories
sudo mkdir /project_name
sudo chown -R yourusername:admin /project_name
2.Find virtualenvwrapper.sh to use in step 3 below, check the following paths:
/Library/Frameworks/Python.framework/Versions/2.6/bin/virtualenvwrapper.sh
/usr/local/bin/virtualenvwrapper.sh
3.Update your profile script (~/.bash_profile or ~/.profile) in a text editor, adding the lines below at the bottom of the file. If you don't have either of these files in your home directory, create a file named .bash_profile in your home directory.
export WORKON_HOME=$HOME/.virtualenvs
source /insert/your/path/to/virtualenvwrapper.sh
4.Quit your Terminal app and restart it. You should see a bunch of folders get created when you restart it. This will only happen once.
5.Make your environment
mkvirtualenv django
(django)$ <- now you are in your new virtualenv
6.To leave your environment:
(django)$ deactivate
7.To enter your environment, quit Terminal again to reset paths so we can test our setup and move into your working directory to checkout a project:
workon django
(django)$ <- you are back in your environment
It seems like that python is not installed in /var/bin/python on your machine. The path seems a bit odd, a more common path is /usr/bin/python.
One way to check where python is installed is to run which python. Try to replace /var/bin/python in the command you use when creating the virtualenv with the result from the which command.
#Try this step by step procedure
1. open terminal
pip install virtualenv
2. cd desktop
desktop> virtualenv env
# A folder named env will appear on your desktop
3. desktop > cd env
#now activate the virtualenv
desktop/env>.\Scripts\activate
# now you will see
(env)c:\...\desktop\env>