How do I set up a configured environment from a cloned repo? - python

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. :)

Related

Cannot execute pip after changing virtualenv folder name

So previously I named my virtual environment "test". After that, I changed it to "testt", and after that I can't access pip commands anymore and it gives me the following error:
Fatal error in launcher: Unable to create process using '"C:\coding\test\test\Scripts\python.exe" "C:\coding\test\testt\Scripts\pip.exe" ': The system cannot find the file specified.
How can I fix this?
You should never rename a virtual Python environment. When creating the virtual environment, the path is hardcoded in several places (see the Scripts/activate* scripts for example).
You could try to replace the hardcoded paths in all files, but I'm not sure how good this works and if this changes between (Python/venv) versions.
Best thing to do is just remove the old virtual environment and create a new one.
If you're using a requirements.txt file, this as as easy as:
py -3.10 -m venv new_env
new_env\Scripts\python.exe -m pip install -r requirements.txt
(example commands are for Windows and Python 3.10, but are similiar for Linux and/or other Python versions)
If you didn't use a requirements.txt file, you could run pip freeze before removing the old virtual environment to see which modules you had installed.
Side note: this method has the advantage that you're actually verifying that your environment is well documented (i.e., the requirements.txt is up-to-date) and that you can reproduce it. This will make it easier to repeat this process in the future (e.g. on another computer) as well.

Configure a Pipenv environment in pycharm

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.

How to activate virtualenv in Cygwin after copying the virtualenv folder

complete beginner here. Trying to build a flask web app. Using Windows 8.
Having some problems activating my python virtualenv in Cygwin. I have been using git shell up till now with no problems.
I copied my folder ("app") into my cygwin home directory and it is set up like so:
app - templates
- static
- flask - env - scripts - python
- ...
- hello.py
- ...
I change directory into the app folder, then when I type the command to activate my virtualenv:
$ source flask/env/scripts/activate
The terminal shows:
(env)
so I assume that it is working, until I double check which python:
$ which python
and that returns my original global python install, not the virtual environment. I've checked the installed packages to double check which python environment I am using.
I use the same command in git shell and it activates the right virtualenv. Where am I going wrong / what do I need to change? Please let me know if you need any more information.
I created a new virtual environment using cygwin and when I activated the new env, it switched to that environment fine. Why won't it work for the folder which I copied in?
I created a new virtual environment using cygwin and when I activated the new env, it switched to that environment fine. Why won't it work for the folder which I copied in?
This last sentence is the real problem. The way you try to activate is correct. The problem is that the virtualenv directory must not be moved.
The activate script inside the virtualenv uses absolute paths internally. If you move the directory, the paths will no longer work, and so which python finds the first valid binary on PATH, which is your global binary.
If you need to move the project to a different location, and the virtualenv together with it, then recreate the virtualenv, do not copy it.
The recommended practice is to have a requirements.txt file, and install packages using pip install -r requirements.txt.
That way, recreating a virtualenv is very easy: create an empty virtualenv, and run the pip ... command. There should be nothing else inside the virtualenv that needs moving, only what pip put there, or other python installer scripts, if you used any (and which you would need to re-run, in addition to pip).

setting up Django Virtual Env error "The executable /var/bin/python (from --python=/var/bin/python) does not exist"

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>

Developing Python Module

I'd like to start developing an existing Python module. It has a source folder and the setup.py script to build and install it. The build script just copies the source files since they're all python scripts.
Currently, I have put the source folder under version control and whenever I make a change I re-build and re-install. This seems a little slow, and it doesn't settle well with me to "commit" my changes to my python install each time I make a modification. How can I cause my import statement to redirect to my development directory?
Use a virtualenv and use python setup.py develop to link your module to the virtual Python environment. This will make your project's Python packages/modules show up on the sys.path without having to run install.
Example:
% virtualenv ~/virtenv
% . ~/virtenv/bin/activate
(virtenv)% cd ~/myproject
(virtenv)% python setup.py develop
Virtualenv was already mentioned.
And as your files are already under version control you could go one step further and use Pip to install your repo (or a specific branch or tag) into your working environment.
See the docs for Pip's editable option:
-e VCS+REPOS_URL[#REV]#egg=PACKAGE, --editable=VCS+REPOS_URL[#REV]#egg=PACKAGE
Install a package directly from a checkout. Source
will be checked out into src/PACKAGE (lower-case) and
installed in-place (using setup.py develop).
Now you can work on the files that pip automatically checked out for you and when you feel like it, you commit your stuff and push it back to the originating repository.
To get a good, general overview concerning Pip and Virtualenv see this post: http://www.saltycrane.com/blog/2009/05/notes-using-pip-and-virtualenv-django
Install the distrubute package then use the developer mode. Just use python setup.py develop --user and that will place path pointers in your user dir location to your workspace.
Change the PYTHONPATH to your source directory. A good idea is to work with an IDE like ECLIPSE that overrides the default PYTHONPATH.

Categories