Experienced Programmer, but new to Python. Using OsGeoLive and PyDev on Eclipse.
A few weeks ago I started a new project in PyDev (my first one). I set the project aside and am only now coming back to it. But when I open Eclipse, I do not see any way to open the project I started. There is no Recent Projects on the File Menu, File > Import does not seem to be what I need. The Project menu has an Open Project item, but it is deactivated. When I open the project's .xml file from Eclipse, it opens it as an editable XML file.
How do I open an existing PyDev project, or alternately, how do I trouble shoot PyDev losing track of the directory structure?
Locate the Package Explorer window and see if there any project folders in there. You also have the option to see "Working Sets", which are convenient to create projects distributed through several folders. Just to make sure, check out if you see something like this (You can display Projects with the prompted submenu):
If you don't see anything there, perhaps your project folder is missing an init.py file, in order to be recognized as a package, which is a general Python standard.
Sorry if this doesn't help much, I cannot leave comments yet.
Related
I have been using PyCharm since I began learning Python because of its amazing UI that helped me learn a great deal about the language. As I progress into more advanced projects, I am beginning to prefer using a text editor / command line combo so that I can build my own venv's and have better access to source control. My question is, how does PyCharm manage custom local packages that I created so that I can import them wherever I want in the directory? For instance a project that I have built exclusively in PyCharm that runs will raise numerous import errors when trying to run that same project in VS code, or even a command line shell (yes I did have the PyCharm created venv activated before running on both attempts). For further examples, here is the project structure I am confused about:
RootDirectory
package_1_folder
__init__.py
pckg_1_class.py
program_using_pckg_1_folder
class_using_pckg1class.py
venv
The above structure has no issues being imported and used in PyCharm, however VS code / Sublime when used with command prompt / gitbash will raise either an ImportError or a ModuleNotFound error. I have even gone as far as adding the desired packages to my laptops windows PATH, using sys.path.append (I know this is not good practice I was only trying to get it to work), and even modified the .pylintrc file with the project path with no success. Any help explaining why these errors are happening would be greatly appreciated :)
NOTE:
I have been able to use the packages in VS code as long as the program importing the module is located at the root directory level, but not in its own folder in the root directory. Again, this statement WILL work in PyCharm, I just want to know how PyCharm is able to achieve this.
After numerous attempts to locate how the system was keeping tack of module within the IDE, I found that my answer was not visible from the IDE. I found a .idea folder in my root directory that contains a few .xml documents that manage the directory including where to read modules from.
I'm using macOS 10.15.4 and PyCharm 2019.3.4
I currently have a folder inside the PyCharmProjects folder (that is automatically created when PyCharm first runs) where I keep projects for a class. I want to move this folder, which contains multiple other folders which each contain PyCharm projects, somewhere else on my computer (like the Desktop). The problem is if I move the folder (or even just a single PyCharm project) the next time I open the project in PyCharm, it says "Invalid python interpreter selected for the project." Now I can manually go into PyCharm preferences and point it to the new location I moved the folder so it can use the correct python interpreter. But this would be tedious to do for every single project I have. (And yes, every project I have uses its own interpreter and virtual environment.)
Is then a way I can move a folder containing multiple PyCharm projects without loosing the references to each of their respective python interpreters?
(Feel free to reword this question or the title.)
PyCharm uses configurations from your home directory. The docs say
macOS
Configuration
~/Library/Preferences/<PRODUCT><VERSION>
Caches
~/Library/Caches/<PRODUCT><VERSION>
Plugins
~/Library/Application Support/<PRODUCT><VERSION>
Logs
~/Library/Logs/<PRODUCT><VERSION>
where <PRODUCT> is PyCharm.
They are xml files. Among them also a list of configured interpreters. They are separate because they are available for all your projects to be chosen as the default interpreter. You'll have to edit the xml files.
For some reason PyCharm does not help with a moved virtualenv directory directly. (see comment from engineer: https://youtrack.jetbrains.com/issue/PY-32435#focus=Comments-27-3139072.0-0)
On the upside, everything else seems to work, except the path to the venv python. That one can be changed through preferences/project preferences/python interpreter. Just click on "add", "existing", and select the python compiler in your project folder.
Try not to select the ".virtualenvs" python compiler, as if you fumble like I did, it seems it's a bit of a pain to get rid of it and go back to the right one. If you do that, renaming the project folder once more gets you back to square one and you get to try again.
Note that I'm using MacOS. YMMV.
I'm trying to follow the tutorial on jetbrains (link: https://www.jetbrains.com/help/pycharm/pytest.html) about using pytest in pycharm so I can work on test driven development. I'm stuck at the part where I'm supposed to create a test for a specific function in the Car.py module (found here: https://www.jetbrains.com/help/pycharm/creating-and-running-your-first-python-project.html#) by hitting ctrl+shift+T and then clicking "Create new test...".
Screenshot of the step in the tutorial I'm stuck at.
When I click "Create new test..." nothing happens. The dialog box which is supposed to pop-up does not appear.
I've gone to Settings>Tools>Python Integrated Tools and changed Default test runner to pytest like I'm supposed to. I checked packages in the Project Interpreter and pytest version 5.3.5 is there which I just installed. I restarted pycharm for good measure. Does anyone know why the dialog box might not be appearing? I'm sure there is a more manual approach to making the test file but the built-in pycharm ability to do this quicker/easier is preferable.
Thanks for answering your own question, you have given me an idea for my solution.
For what reason so ever, I was not providing PyCharm a root directory for my project so it was not recognising my files.
I changed it under:
Preferences > Project:"your project name" > Project Structure
It was a silly mistake in my case. I was not opening the proper project folder. Instead I was opening parent folder.
My hierarchy was
E:\Projects\SampleProject
Instead of opening SampleProject in PyCharm, I was opening Projects directory whole.
I think PyCharm will only open this if it recognizes valid structure of the project.
Press Ctrl+Alt+S to open the Settings window, go to Project <project name> > Project Structure and mark your source folders as Sources (highlighted as blue in my version of PyCharm). Then you should be able to create tests for them.
I've create a pydev project in eclipse.
At the top level of my workspace I can see these two files:
.project
.pydevproject
I can also see these in each of my subfolders that contain my actual projects.
At the top of my workspace there is also a
.metadata. folder.
What should I commit to source control?
Ie what can I delete and still be able to open the project with minimal effort (hopefully entirely automated regeneration of files)? If this was Visual Studios C++ project the answer would be to keep just the ".sln", "vcxproj" and "vcxproj.filters" because the "vs" folder and "suo" files will autogenerate on openning. I've tried to delete the ".metadata" folder, but after that nothing appears to load in my workspace.
Also, I am working with someone not using an IDE. What eclipse files do we need to update to keep in sync?
Disclaimer: I am not familiar with PyDev, just with Eclipse in general. You definitely should not check in the .metadata folder. That one is for your Eclipse workspace as a whole and contains your personal configuration. (That's why your workspace appeared empty after you deleted that folder.) In fact, you should not check in your workspace folder at all, but just the several project folders within it.
Whether to check in the .project files is sort of a matter of taste. Those contain project specific information and settings and with those its easier to import the project into Eclipse, but you can import the project without those, too, it's just a bit more work. If other developers are not using Eclipse, those are useless for them. In the worst case, your co-developers will delete those files from source control and when you update your project later, they are deleted on your end, too, messing up your project.
About deleting the files: Note that there is a difference between not checking files into version control and deleting them locally. So in short: Do not commit those files into version control, but don't delete them locally, either. Depending on what sort of version control you are using, you can set it to ignore those files.
I'm new to PyDev and fairly rusty in Python. Trying to get back into it with a simple reddit app first. So here's my setup:
I have 2 PyDev projects: reddit and pylons (reddit api.py imports from pylons).
When I go into any file in the reddit project I get "unresolved import" for anything that tries to import from pylons. In reddit's PYTHONPATH, I've tried adding /pylons and /pylons/pylons, but whenever I refresh the project, PyDev seems to rename my references to /reddit and /reddit/pylons.
How do I fix this? How do I properly add the pylons project into the PYTHONPATH of reddit?
The most proper way to include another project source into your PYTHONPATH is to make a reference from your project to another project. For this make next steps:
Choose your project in PyDev Package Explorer (usually tree-like panel on the left).
Press Alt + Enter.
Click Project References tab.
Check Pylons project in a tab content frame.
Note, that path with source of both projects must be added to python path for Eclipse to build references for them.
Note #2 Also when you install some new Python packages you need to reindex them at Window > Preferences > PyDev > Interpreter - Python.
Since Rostyslav's solution is not working for you, perhaps you should try to add pylons as an external library. At reddit's Properties window click PyDev-PYTHONPATH tab and the External Libraries tab. Click Add source folder and find pylons's source folder. Changes to external libraries are not monitored. So you have to use Force restore internal info when pydev can't find new references (tipically when you make changes to pylons's structure).