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.
Related
I'm a bit confused on this and can't find a satisfactory answer searching elsewhere - everything is about using external libraries in some way or another.
In my PyCharm projects, I've got your project root directory, which contains a venv. This venv of course contains the python executable relative to the project, as well as the relevant site-packages and modules I've downloaded via pip or whatever.
But there's always an External Libraries section, that has it's own Python executable, venv, .gitignore, site-packages, etc.
Is this normal? What's the purpose of having two venvs in the same project?
Thanks!
You only have one venv normally in your Project
The other Python Executable should be the global one.
Normally you use a venv to keep track of the needed Packages for this specific project. So that you don't confuse other Packages with other projects or have dependency/Version Issues
If you want you can also use the global Installation of Python which would not create a venv
I have been using Python with PyCharm with virtual environments and GitHub and there has been a lot of trial and error. I want to start fresh. I uninstalled Python and PyCharm with Windows's remove apps.
When uninstalling PyCharm I clicked option to delete everything there was to delete. Then I reinstalled restarted Windows and installed Python again and then PyCharm. When I launched PyCharm everything was exactly the same as before: same projects, same interpreters / virtual environments, same dependencies and same git capabilities.
I would really like to start fresh since now I have at least some more knowledge of these things, but can't seem to do so. I am not worried about losing my projects since the important ones are on GitHub.
You will have to manually delete a few directories used by the IDE and individual projects. This is an important fail-safe so you don't lose all your work and configurations should you need to reinstall PyCharm or uninstall it by mistake.
See the documentation:
Directories used by the IDE
By default, PyCharm stores user-specific files for each IDE instance (configuration, caches, plugins, logs, and so on) in the user's home directory. However, you can change the location for storing those files, if necessary.
This JetBrains blog post is also worth considering Directories used by the IDE to store settings, caches, plugins and logs.
For example,
same interpreters / virtual environments
An interpreter is just a directory with a Python executable and installed libraries. Although the PyCharm IDE can index and keep track of your interpreters they are independent and you'll have to delete them separately when needed.
same projects
Each individual project contains a directory called .idea where the IDE settings for that project are stored. You can delete the .idea directory and keep the source code.
Should I create a directory in my virtualenv and save the source code for that specific project there?
Thanks in advance
You're not required to have them related in any way. As long as your env is activated, it doesn't matter where it is.
But what's usually easiest is:
Create an empty directory for your project.
Create the virtualenv under that project directory.
Put the source in a src directory under that project directory (or, for really simple projects, just drop it in the project directory).
That way you can check the env settings into version control alongside your code, and if you use an auto-venv tool it'll activate the env every time you cd into the project directory, and so on.
As a side note, if you're just learning this stuff today, you might want to consider learning pipenv instead of using raw virtual environments.
You can save your project anywhere. But you should activate the virtual environment before working on that project.
You can activate the virtual environment using the following command.
source path-to-virtualenvironment/bin/activate
After activating the virtual environment move to your project location.
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.
I just copied my Flask project from one machine to another. I have same version of Python installed on both the machines. When I loaded the project in the new machine, it said my virtual environment is unavailable. So I initially tried to install it from requirements.txt file but it failed without any helpful error message.
So I deleted the virtual env in Visual Studio and tried to create another one. Now it complains that it cannot find any Python interpreters on my machine. I tried uninstall/reinstall Python but it didn't work. Also, the Python location is added in the PATH environment variable and all the modules in the requirements.txt file are downloaded from pip individually.
So the modules are installed, python is installed and the project is there but the virtual env won't setup because of the below reason. Any way that I can fix this ? This is PTVS15 and Python 3.6.1
Fixed it myself. I went ahead and added the environment manually by specifying the Python installation paths in the Add Environment tab. It took a while to detect the interpreter even in this way but it finally worked. I am now able to build my app.