How to configure code completion for Django based projects in PyDev? - django

I am playing with a simple project based on Django framework. My IDE is PyDev/Eclipse.
I cannot make code completion work for Django code, but it works fine for standard Python libraries.
I tried to add Django dir (in my case C:\Program Files\Python26\Lib\site-packages\django) to PYTHONPATH both on PyDev level (Window->Preferences->PyDev->Interpreter - Python->libraries) and on a project level (Project->Properties->PyDev - PYTHONPATH) - no luck so far.
Can you please advise what I am missing here (preferably without installing PyDev extensions).

Ok I give it another try.
Eclipse in C:\test\eclipse
Python 2.6.2 in C:\test\python-2.6.2
Django 1.0.2 final in C:\test\python-2.6.2\Lib\site-packages -> only the actual django folder not the docs, example, and so on. I did this without running setup.py as descriped in the INSTALL file.
Added C:\test\python-2.6.2 and C:\test\python-2.6.2\Lib\site-packages to the PATH variable
As described here I set the Interpreter in Eclipse by Window > preferences > pydev > Interpreter > Python. This automatically included a whole bunch of things under System libs like (C:\test\python-2.6.2\;C:\test\python-2.6.2\DLLs;C:\test\python-2.6.2\lib\site-packages;....). A whole bunch of Forced Builtins are also found.
Then I made a new "Pydev Project" added a package and there a new module with a class and a module which imports the class and calls a function from it. During writing this pressed Crtl+Space several times, and builtins as well as the new stuff from my Module where shown by code completion.

I suggest Configuring pydev to work with django and
Getting started Eclipse/Pyddev
In the latter one there is a section specifically for code completion which mentions a problem with firewall or shell timeout. And in another section he mentions problems when (as in your case) the eclipse installations has spaces in the filepath

I solved setting the PYTHONPATH too.
In the pallet Projects, right-click on the project -> properties
In the PYTHONPATH configuration you have to put the folder that contains your project as a external folder.
Exemple:
/var/www/my_project
PYTHONPATH=/var/www/

Related

VS2017 Installer project output does not replace the current installation

I have a standard windows forms application that is being deployed using the VS2017 setup project. When opening the setup project using the "File System", I added to the application folder the following:
Primary output from the win forms app.
The EPPlus library's dll.
Some excel files.
The setup project gives the output .msi package just fine. The problem is, when I run the .msi output after building the setup project (of course after building the source project) and run the application, I do not see my updates, even the files on C:\Program Files .... directory are not modified. I tried changing the product code and the increasing the version and it does not work. My questions are:
Besides removing and installing the program again, is there anyway to make the installer package actually updating the software's installation?
How to avoid the problem in #1 no matter how much I update the software?
What is the cause and how to avoid this error "Another version of this product is already installed"? I'm not sure of what I did for it to pop up.
If I want some part of the source code to be in a separate dll, is it as simple as adding a class library project and adding its output to the setup project?
Thank you very much.
The way you do the upgrade is to use the RemovePreviousVersions project setting. The steps are:
Increment the setup project's version and accept the changes, this will include a change of ProductCode.
Make sure that RemovePreviousVersions is set true.
The UpgradeCode (setup project properties) needs to be the same so don't change it.
Increment the file versions of the binaries that need updating (that's the standard rule about updating versioned binaries).
The resulting MSI will do a major upgrade (in Windows Installer terminology) and upgrade the older version, replacing it with your new product MSI. Note that an upgrade will work only with the same context of install. An Everyone will not upgrade a Just me, so that will result in two entries in Programs and Features. Doing the install creating a verbose log and searching foe FindRelatedProducts entries will tell you if it found the upgrade or not. msiexec /I [path to msi file] /l*vx [path to a text log file]
There's a longer explanation here:
https://www.red-gate.com/simple-talk/dotnet/visual-studio/updates-to-setup-projects/?_ga=2.138201520.1662048302.1514485579-1682631157.1514485579
which is old but relevant. and doesn't mention the requirement to update binary file versions (it wasn't needed with early VS setup projects).

How to configure pylint for both python2 and python3 in vs code

I have two projects in two windows , one in python2 and other in python3.
Is there anyway I can use both pylint for python2 and python3 in vscode for different projects on the fly ?
I tried, but I can't use both of them. Either I can able to set python2 pylint or the python3 one.
Yes, there is a way.
You can set one interpreter for each folder (project) you have open in vscode. And this will dictate the linting (asuming you have the modules installed for each interpreter). This way you can have two different projects open at the same time and each will use their set interpreter and lintern.
The automatic way
The ideal way to select the interpreter for your current project-folder is to open the command palette (F1) and type "Python: Select Workspace Interpreter" and choose from the dropdown list (all while you have your project open). And that's it. Vscode will use that interpreter and lintern.
The manual way
Now, if when you try to select an interpreter like I described above you get a message like this: "There are no entries to select from" even though you have both interpreters installed, like it happened to me (when I tried on Windows, I think maybe because of the Python Launcher for Windows). You can still select the interpreter. You're just going to have to do it manually.
While you have your project open, on de command palette write "Preferences: Open Workspace Settings" and hit enter. This will create and open an empty settings.json file in a hidden .vscode folder inside your project folder. In this file you can set the exact python interpreter you want to use in the project. For example, for python 2, like this:
"python.pythonPath": "C:\\Python27\\python.exe"
With that you should be able to lint and debug with an specific interpreter.

Pyinstaller | Extrected Exe unable to find sub module

I am new in Python. Currently Using Python 2.7. As a current exercise I am converting Python Script to exe file through PyInstaller. I am finding trouble in finding certain modules through generated exe which are working perfectly fine while I am running through Python Script.
I have created exe through --onefile option in PyInstaller. As a part of exercise I have already done the following points,
Verified that python file is exist at particular locaion(temp location) including python compiled file.
I updated sys.path entries to find python at particular(temp) location.
I also verified that imp.findModules able to find the module but imp.loadModule failed to load the module while running through exe file.
Note that while I am running the python file from command line it works fine, it only gives error while I am creating exe file.
Problem Image is attached here.
Any help would be appreciated.
Regards,
Sunay Shah
I have seen that many people are facing the issue. I fixed the Issue and following is the solution for the same.
During packaging with the help of PyInstaller , I found out that PyInstaller is analyzing the given python file and imports packages itself which it found during the analysis phase. Those which packages which are found and would be zipped during the packaging can be seen in the build folder created by PyInstaller (out00-Analysis.toc,out00-PKG.toc,out00-PYZ.toc,out01-Tree.toc,warnXXX.txt file ) are the important files to look into.
During my problem analysis I found that my certain packages are not imported during the Analysis phase. I came to know on digging that we need to include those packages in data files. So I copied almost all my packages that are required into data section in .spec file. Still problem continues. I dig little more and found that although artifacts are packaged they are unable to import during execution.
I gone through some in more details and found out that issue was around that during runtime certain modules were not able to import by PyInstaller. I found that issue can be resolved with the help of hidden-imports. I added missing modules in hidden-import section which resolved the issue.
Making Long story short , following are the key take away from my problem
1. Create a Build with default option , resolve all your problems
2. Include all the required modules into the build with datas section which were not found out by PyInstaller.
3. Add hidden imports which were not imported by Pyinstaller. ( e.g if abc.contrib.usages module is not loaded during runtime, add that into hiddeniports sectin.
4. Once created exe works with default option use --onefile to create the build.
5. Best way to resolve your problems is analyze all the files created in build folder during the creation of the build.
Hope this will help some one to fix there issues.
Regards,
Sunay Shah

Eclipse CDT Kepler Importing Makefile project

I would love to import a Makefile project from Eclipse, and have all the different includes path that the compiler uses to create correctly my Eclipse project.
Unfortunately, those path, specified on the command line by a "-I" don't show up in Project Explorer and I have to add them by hand.
I am currently importing the project using the standard "Import project from Makefile" built in Eclipse.
If I'm not wrong there was an autodiscovery option in older versions of Eclipse, but it's not there anymore.
How do you do for having all your include paths set up without too much hassle?
The trick is NOT to use
File->New->Makefile Project with Existing Code
but to use
File->New->C++ Project
and then to select
Makefile project->Empty project.
After you set up such a dummy project, you simply copy your existing source to that project directory, hit F5 (i.e. Refresh) and change the build command to use your Makefile.
I was able to get this to work using Luna. I imported using File->New->C++->Makefile Project with Existing Code.
Prior to launching eclipse, you have to be sure to source any files that set required environment variables.
I did have some build options which were not the standard all and clean, so I had to add those configurations individually.
source files to setup your environment.
Launch Eclipse
Import C++ Makefile project
Setup Build options.
Click the hammer.

How to set up an environment in Eclipse CDT by script per project?

I have got several projects in my workspace. I have a script which set a different environment for each project. How can i get Eclipse CDT to use this script to set up the environment instead of setting everything by hand for each project?
Thanks.
You can translate your script into java, then develop a plug-in to call the API of CDT to apply the environment.
Eclipse CDT Properties for the C/C++ Build has an "Environment" page. You can set variables in this (per project) and either replace or append the native environment.
Right click your project and choose Properties
Expand the C/C++ Build item and choose Environment. From there you can modify the properties page.
Unless you have something complicated in your script, this could replace the need for a script altogether. Check out the other settings in the properties page - these might help you to customize each project as you need.