I downloaded my old project from the repository and there are a lot of unresolved references now, how can I fix them?
If you are working with a virtualenv you have to configure your project to let Pycharm know what interpreter should be used and where are its dependencies.
https://www.jetbrains.com/help/pycharm/2016.1/adding-existing-virtual-environment.html
You should configure your Python interpreter and get Django installed. In the documentation you 'll see:
Selecting Python interpreter for a project
An interpreter can be made the project default when is it added.
To configure Python SDK for the current project follow these steps:
Open the Settings dialog box, and click Project Interpreter page.
In the Projects pane, choose the desired project.
For the selected project, choose SDK from the list of available Python interpreters and virtual environments. This list includes:
Python interpreters, which reside in standard locations.
Virtual environments, which reside under the project folder, or under the folder specified as an environment variable WORKON_HOME.
Other Python interpreters, installed locally or remotely.
If the desired interpreter is not in the list, click cogwheel button, and configure the desired interpreter as described in the
section Configuring Available Python Interpreters.
Apply changes.
Related
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.
when I clone a github repository to my pycharm it says that I don't have any python interpreters for that project, but when I open the terminal (pycharm terminal) and type "python name_of_the_file.py" it runs the program without problems. Do I have to set up a python interpreter for the project or not?
ps: pycharm doesn't give any kind of error when I import some module for that project (bult-in module and not bult-in modules)
You just need to tell PyCharm where your Python interpreter is. Go to File -> Project Structure -> Project and select a Project SDK. I suggest creating a new virtual environment for each project.
Opening the terminal and typing python uses the system's PATH variable to find the executable. PyCharm doesn't use this automatically and you have to set it up.
I have a shared flask web project I am working on with 2 other developers, one of the developers initialized the venv on his pc, uploaded his project structure to github from where I cloned his repo.
Now I when I start vscode and open the project folder, python does not auto detect the venv and asks if it should set is as the interpreter, the only option I have is the default system wide python install, and not the venv python interpreter.
I tried adding it to the list by using the command python:select interpreter and then finding the python.exe inside the venv/scripts folder, but this does not work and vscode still asks for a interpreter.
I also tried manually adding it inside of my workspace settings.json file like so
"python.pythonPath": "C:\\laragon\\www\\Proftaak\\venv\\Scripts\\python.exe"/
But vscode also gives an error on this saying the interpreter is not valid.
How would I fix this?
This is not expected to work as virtual environments are not designed or meant to be movable. They are meant to be created on each machine you need a virtual environment on. As such, I suspect that the virtual environment does not work outside of VS Code which could prevent it from selecting it as a possible working environment.
My PyCharm ver was working fine, but I broke it.
I wanted to have the matplotlib, so I uninstalled my Python installation and installed WinPython, which works fine. But it was installed in the folder where installation program was (i.e. download folder).
When I try to run a python program in PyCharm a message comes up saying
Cannot run program c:\python34\python.
I tried to Google "how to change python directory" and came up with the following answer in Stack Overflow:
In project settings Select Project Interpreter and then Python Interpreters
My project settings does not have a tab for Project Interpreter, it has:
Appearence
Editor
Plugins
Version Control
Project: bitcoin
Build, Execution
Frameworks
Tools
It's Project: (project name) → Project Interpreter → "Gear" icon → Add local.
This change will affect your current project only. To change the default interpreter for new projects, go to File → Default Settings....
Also, there's a search box on top of the setting window. Use it if you can't find some option.
Or you can try registering WinPython as a standard Python distribution.
i am following the tutorial found here: http://www.windowsazure.com/en-us/documentation/articles/cloud-services-web-sites-python-django-app-with-ptvs/
I already had django installed on my system. After following the instructions in this tutorial, i noticed that it seemed to have installed django again, but this time under my project's folder (myproject/env/Lib/site-packages).
Why is this?
The other issue i am having is that if i try to import certain libraries using the visual studio editor, it's unable to find the import. However, if do this in the Interactive window, it does recognize the imports. Also, if create a stand-along python (not django) project, i am able to import the libraries fine.
Any thoughts on why this is happening and how to resolve?
The tutorial uses Python virtual environments (virtualenv), which you need in order to deploy your website to Azure. A virtual environment, basically, is an isolated Python environment with its own set of libraries (site-packages etc) that is distinct from your main interpreter. It allows you to have specific versions of packages that you need just for that particular website, and different from the same for some other website of yours.
If you don't plan to deploy it to Azure, you don't need a virtual env - you can skip the step creating it, and instead install Django and other packages directly into your main interpreter. If you do plan to deploy to Azure, you need the virtual env, because the main interpreter installed on the Azure VM will not have any modules other than those in the standard library.
The reason why Python Interactive window lets you import the packages is that the instance you're working with is for your main interpreter. Every registered interpreter, and every virtual env in an opened project, has its own separate Python Interactive window. You can open the window for your virtual env from the Python Environments window, which is available via Tools -> Python Tools -> Python Environments.