How should I move my completed Django Project in a Virtual Environment? - python

I started learning django a few days back and started a project, by luck the project made is good and I'm thinking to deploy it. However I didn't initiate it in virtual environment. have made a virtual environment now and want to move project to that. I want to know how can I do that ? I have created requirements.txt whoever it has included all the irrelevant library names. How can I get rid of them and have only that are required for the project.

Django is completely unrelated to the environment you run it on.
The environment represents which python version are you using (2,3...) and the libraries installed.
To answer your question, the only thing you need to do is run your manage.py commands from the python executable in the new virtual environment. Of course install all of the necessary libraries in the new environment if you haven't already did so.
It might be a problem if you created a python3 environment while the one you created was in python2, but at that point it's a code portability issue.

Related

VS Code does not recognise imports because of docker

Good day. I was using virtual environment in development stage (for python projects, of course). But one day, I decided to do everything using best practices, and followed one course. In that course, tutor uses docker-compose for all operations, and installs all dependencies to inside docker container. But I'm using vs code, and since no virtual environment is created, vs code does not recognize imports, because it looks at the main interpreter, in which I don't have those dependencies. One way is to install all dependencies to the main interpreter, and I think it is not recommended. Another way, I think, is to create a virtual env for just containing the dependencies for vs code to refer it. But I'm not sure it is best practice or not. What is the best way of developing a python project using docker, and vs code ?
Fun fact: In tutors Vs code, there is no problem :)
The first thing to understand is that the interpreter of the virtual environment is isolated from the real environment, so there is no need to call the dependencies in the virtual environment while using the main interpreter.
I think the best way is to unify all operations in the virtual environment, so that the environment will not be disordered.
You can also refer to this document for more information about vscode and docker
morning,here is an example,https://github.com/miguelgrinberg/flasky
you can learn from this project struct.
in a word.you can use virtualenv in your develop env,when you commit your code,you may ingore venv dir,when you deploy your project ,you may use docker-compose to deploy.
feel free

How to distribute a Python virtual environment?

I have created a Python virtual environment using virtualenv for Python 2.7.18 64 bit and another virtual environment using venv for Python 3.5.4 64 bit.
I was hoping to be able to commit these items into version control so that other users of the project could access them without having to setup a Python environment themselves. Another issue is that some of the work stations will not have access to internet to easily create a virtual environment from scratch, so using a requirements.txt file is not a valid solution.
It seems like there are a fair amount of issues preventing a virtual environment (whether using virtualenv or venv) from being easily 'copied' and executed on another system.
Is what I am describing even possible? I have tried tinkering with the 'activate' scripts to remove some of the hard coded pathing but that doesn't seem to do the trick.
Thanks
Have you considered using Docker? If you just have an image (or use docker-compose for multiple images), the user will not need to start a virtual environment.

Fundamentals question: Django + Python Virtual Env + pyCharm and CLI -- are two separate virtual environments required?

Bottom Line:
I can get everything to work by configuring two separate virtual environments, one for pyCharm and one for the CLI. Is this really necessary or should I be able to use 1 virtual environment for both as I expected?
More Detailed explanation:
I'm very new so this is probably a facepalm type of question so i'll try to be terse.
I'm using Linux Mint, Python 3.6, django 3.0.3, and pyCharm 2019.3.1.
I can create a virtual env using venv in the cli and it works.
I can also create a NEW virtual env in pyCharm through the settings: Project: Interpreter interface, and it works, however it doesn't have venv as an option, it only has virtualenv.
But if I try to activate the virtual env i created in pyCharm from the cli (using virtualenv of course, not venv), it fails hard and thinks i'm using python 2.7 which isn't even installed on my system. If it try to point pyCharm at the virtual env I setup on the cli, I get an error 134.
Is this just a known/expected issue? Must I have two virtual environments for every project I want to access via both pyCharm AND the cli? And I assume this is unrelated but I also find it odd that pyCharm lists my interpreter as python 3.7, which also is not installed on my system. I'm using 3.6 alone.
Thanks for your time.
At this time, I'm going to just answer this as: you need a separate virtual env for each (pyCharm and CLI) as this approach is not difficult or time-consuming and I have not had any issues working in this way.

How to export the environment of Python project

I am using Pycharm Community Edition 2019.2.. I imported a Python project from another computer. I just copied the files and then created a new project the directory. There are multiple modules that are imported in this project that I have not installed on my computer. I want to know what is the best way to automatically manage all the dependencies of this project.
I created a virtual environment(venv) in the original project. Can you export this somehow? Is this even the right path to solve this problem? The virtual is supposed to manage dependencies, though I haven't read anything about exporting settings, it mostly about isolating dependencies and settings. I've been looking at conda and pipenv as well, but I focusing on virtual environment before I try to go laterally in problem solving.

Python Tools for Visual Studio & virtualenv - can use packages only present in deactivated env

I'm working on a Django project in VS 2015 Community with PTVS, which has been very useful for a free tool. I recently realized that I should be using virtual environments during development, and found out that Python 3 includes this feature by default, and PTVS 2.0+ supports it- cool!
I created a couple environments as an experiment, and in one I installed the celery[redis] bundle since I'm trying to figure out how to implement a background task. I was having trouble getting the basic celery tutorial task to work, so I decided to remove the environment from my Django project, deactivate it, and start over.
However, once I removed it via PTVS and ran deactivate from the command line inside the environment directory, I could still run celery commands from my top-level project directory. I've never installed celery globally- only to my test environment via the Python Environments menu in PTVS.
Why is this? Am I thinking of virtual environments as too similar to truly discrete environments such as containers? My impression from reading PTVS venv documentation is that if a package is present in a virtual environment which is then deactivated, I shouldn't be able to use it in other environments (or globally). I thought it might be an issue with my Windows PATH, but I didn't see anything related to Python or celery.
Apologies if this is a duplicate- it's been difficult to find questions on the PTVS implementation of venv rather than Python + virtualenv in general.

Categories