Running ODOO 10 from eclipse on Windows 10 - missing information - python

Where is the odoo class and module defined? What should the pythonpath be?
I'm having problems setting up ODOO 10 community to run from Eclipse on Windows (10). This boils down to two problems: I can't find where the odoo class is defined so cannot import the odoo module, and I don't know what the PYTHONPATH should be.
Details:
My main module in the Eclipse debug configuration is set to oddomain.py (renamed from odoo, in the setup folder) with the code:
# set server timezone in UTC before time module imported
# Israel time zone is IST so I'm hoping this will work
__import__('os').environ['TZ'] = 'IST'
__import__('pkg_resources').declare_namespace('odoo.addons')
if __name__ == "__main__":
odoo.cli.main()
I get: missing odoo module from path
I set up ODOO 10 community in eclipse on windows 10. I learned how to do it from comparing these posts:
Installing ODOO 10 Source,
How to debug ODOO in Eclipse in Debian
and this old ​post: How to debug ODOO in Eclipse under windows
I'm running on MS Windows 10.
I have eclipse with Pydev installed.
I have the recommended python version (2.7.9) installed
I have the Postgres set up ok. (with BigSQL)
I have forked the odoo project on github and have the clone from github, locally.
I have the project set with the pydev nature.
I have all the packages installed by editing requirements.txt and running pip install -r requirements.txt in a cmd window in the odoo project directory.
I set up the odoo.conf with passwords for the postgres admin and odoo correctly.
I renamed the setup/odoo file to setup/odoomain.py and after reopening it in eclipse, it is recognized as python and I can set breakpoints. (calling it odoo.py was causing a problem, so I called it odoomain.py)
I set up the debug configuration of pydev to run the setup/odoomain.py as the main.
But I can't find the where the odoo class is defined, and therefore can't import the odoo module! Where is it defined?
What should the PYTHONPATH for the project be? I set it in Eclipse:Project/Options)...
It is now set to
/$/PROJECT_DIR_Name)/odoo/addons
Where is the odoo module defined, and how do I import it? Is it something to do with the PYTHONPATH?

OK the problem was twosome.
First of all I had to correct the pythonpath to include the root, and to include the odoo path. So now I have the PYTHONPATH set to 3 places.
/$/PROJECT_DIR_Name)/odoo
/$/PROJECT_DIR_Name)
/$/PROJECT_DIR_Name)/odoo/addons
In order to determine the correct path, you have to do "import odoo" in a python window from different paths (by changing directory in COMMAND window and running python again) and until it works, and set that
To set the pythonpath in eclipse:
Right-click on the project:
PyDev
Set as Pydev Project
Right-click on the project
Properties
PyDev - PYTHONPATH
Source Folders tab
Add source folder
It works only if I add the root as the SECOND path, and only if all three are there.
Then I had to correct my debug configuration (by editing the "variable") as follows: CORRECT
`--config=C:\MyPath\MyOdooProject\debian\odoo.conf`
Instead I had used the Browse and added the --config to get: WRONG
`--config=C:\MyPath\MyOdooProject\debian\`
And finally I had to run the Postgres on windows and connect to it in the PgAdmin. (I configured it already as requested and had the credentials listed in my debian/odoo.conf as explained.)
Everything runs ok now!! Thanks to Pham Tung for showing me the light!!

Related

Import could not be resolved/could not be resolved from source Pylance in VS Code using Python 3.9.2 on Windows 10

My Flask App server is running but I have three imports that cannot be resolved.
I have tried:
reinstalling the imports individually
reinstalling requirements.txt
I configured VSCode Workspace with an extra path to my project folder (there is now a .vscode file within the root of my project folder where it was not before)
I have updated my venv path settings in VSCode
Here is my file structure:
- > .vscode
- > client *(React front end)*
- > data
- > server *(Python/Flask back end)*
- > app
- > venv
- config.py
- README.md
- requirements.txt *(this contains the 3 unresolved, along with several that are resolving)*
- .env
- .flaskenv
- .gitignore
- requirements.txt
Unfortunately none of these things have resolved my imports issue and my routes are still not working. Any ideas/suggestions?
Open the Command Palette (Ctrl+Shift+P), then select the Python: Select Interpreter. From the list, select the virtual environment in your project folder that starts with .env.
Run Terminal: Create New Integrated Terminal (Ctrl+Shift+` or from the Command Palette), which creates a terminal and automatically activates the virtual environment by running its activation script.
Install sqlalchemy and mongoengine with command pip install. Once installing them successfully, there will intellisense when you import them and no warnings shown.
Besides, the folder .vscode is to store Workspace settings as well as debugging and task configurations.
If you are using a virtual environment, and even after trying pip installing all the necessary libraries, you have to select the python interpreter that exists in the virtual environment folder.
(Ctrl+Shift+P) then search for "Python: Select Interpreter"
Click "Enter interpreter path" followed by "Find.."
Navigate to your project virtual environment folder
Go into "Scripts" folder and then select "python.exe" as the interpreter.
These steps allow you to select the right python interpreter associated with the project's virtual environment.
Open the Command Palette (Ctrl+Shift+P), then select Python: Clear Cache and Reload window.
Voila, all the import errors vanished.
I specified a path to the python interpreter I'm using within the settings.json file contained in the project repo's .vscode folder.
"python.pythonPath": "path-to-interpreter.python.exe"
Thanks to the following resource! https://dev.to/climentea/how-to-solve-pylance-missing-imports-in-vscode-359b
I ran into this error after an upgrade of my local python version (brew -> manual install), even though the specified interpreter was already /usr/local/bin/python3.
CMD + Shift + P and re-selecting the [same] interpreter fixed the error.
In hindsight, I suspect that a restart of VSCode could have also fixed this. 🤷‍♂️
Perhaps VSCode is using the incorrect Python path for this reason. A base interpreter should be used instead of the vscode interpreter, if necessary.
After verifying my Python interpreter was sourced correctly in VS Code, I simply cleaned my env and reinstalled the project locally and the import errors disappeared. I personally had an odd VS Code/Pylance cache and reinstalling the dependencies and modules fixed it for me.
I was getting the very same error you have and none of the solutions presented here worked me.
I work on a windows machine. I use miniconda to manage my virtual environments. And when I'm coding I launch every program from the command prompt (cmd), including Vscode.
Even tough inside Vscode the python evironment was correctly settled I was getting the very same import error that you mention. The interesting part of it was that I wasn't having any problems to run the code, it was working as usuall. But when coding I wasn't able to see the functions related to the libraries with the import error.
The solution:
Activate the correct conda env for the project before launch Vscode from the command prompt.
Why does this happen?
I BELIVE that this happen because when you don't activate any conda env before launch Vscode. The base conda env is loaded as default. That generates the import conflict. (You can chek this out installing those packagues into the environment and running everything just as you have been doing)

'Cannot setup a Python SDK' in PyCharm project using virtualenv after OS reinstallation

I re-installed windows and opened an existing Pycharm project and get the error 'SDK seems invalid' in Settings > Project Interpreter.
The project interpreter path is pointing to python in the venv:
MyProject\venv\Scripts\python.exe
I tried re-adding python.exe:
Thats when I get the error:
Update: here is an error from idea.log, a lot of other issues for virtual environments seem to be with windows environment variables and system paths:
2018-09-28 19:50:40,275 [ 17601] INFO - hon.packaging.PyPIPackageCache - Loaded 153296 packages from C:\Users\Matt\.PyCharm2018.2\system\python_packages\pypi-cache.json
2018-09-28 19:50:40,816 [ 18142] INFO - rains.python.sdk.PythonSdkType - Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00000fa8 (most recent call first):
Exit code -1073740791
2018-09-28 19:50:40,816 [ 18142] ERROR - ns.python.sdk.PythonSdkUpdater - Failed to determine Python's sys.path value:
STDOUT:
STDERR: Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00000fa8 (most recent call first):
com.jetbrains.python.sdk.InvalidSdkException: Failed to determine Python's sys.path value:
STDOUT:
STDERR: Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
What solution is: Check out venv\pyvenv.cfg and provide a valid path to the basic python installation.
What has most probably happend:
After reinstalling your OS, you have no base python interpreter reinstalled or you have installed it at different location than before. Thus your virtual environment fails to locate the python installation. Virtual environment implies that all libraries and settings are isolated from other projects. It does not provide an isolated python installation. You still need your base python that had been used for venv creation.
My case: I have a project in a network share and try accessing it from different computers. The base python paths depend on the very PC. The solution above works fine for me. Unfortunatelly, I need to update pyvenv.cfg depending on the PC in use.
P.S. I believe that there is an environment variable to overide the venv config value. I only tried to set PYTHONPATH=C:\Anaconda3\envs\python37 on Windows and then to activate venv. It did no effect and I gave it up.
Here's what solved my problem when I faced the exact same issue
Navigate to Project Interpreter, right side of the selection box, click the gear icon, it will show two options add & show all.
Click show all, if you see the previous existence from the same directory delete that. Click on add or + sign to add a new interpreter and navigate to your project path, navigate down to the virtual environment directory.
venv/bin/{select the python executable with the version code i.e if you are using python3.6 select python3.6}
Once selected, you can now click the notice that says install packaging tools, hit apply and done.
Most probably, some path to Python environment that PyCharm tries to use has become invalid somewhere. There are (at least) two primary suspects:
Path to your virtualenv in PyCharm settings
PyCharm needs to know the path to your environment to run things in it. So, if that path changed, PyCharm's saved path has become invalid.
Go to the interpreter settings for your project in File->Settings...->Project interpreter->(Gear icon)->Show all...:
Then delete and recreate the necessary entries. Or edit them and specify correct paths.
E.g. this is what my list looks like after I deleted an Anaconda installation:
Path in the virtualenv to its base installation
Since virtualenv is not a full installation, it must have a path to its base installation stored somewhere to be able to use files from there.
As of this writing, virtualenv (v16.0.0) in Windows is implemented like this:
The real python.exe and several other files are copied into the virtualenv's subtree
In Lib\orig-prefix.txt, the path to the base installation is stored. It is used to add the base installation's Lib to sys.path via a custom site.py.
So, if the path in that file becomes invalid, the virtualenv's Python interpreter will be unable to find any standard modules except those few that were copied. Which perfectly fits your symptoms.
I currently have the same issue, that I can't install any package tool in Pycharm and that freak me out. Here is the step I fixed it, just want to share. OuO.
Step 1
Find show all in the right corner of a setting icon
Step 2
Click the + icon to open Add python Interpreter
Step 3
In New environment 's Location Under Virtualenv Environment select file
Step 4
Find your Pycharm file and make an empty file under it and click OK and keep click OK
Step 5
Now in Project Interpreter select the empty file you just create and now you should be fine to install Pycharm package.Hope this solve your problem.
In my case the problem was because I was using WSL to host my project so the project address used by PyCharm to create and select the venv was wrong. Instead of using the option Virtualenv Environment to create the environment:
You need to select the WSL option from the side bar and then enter the path to your new or existing venv.
Nothing above worked for me
I made a simple change , Hope it works for you too !!
It happens due to conflict in storing python.exe , In my case it was in F:\ drive
Solution :- Pycharm expects python.exe file to be present in some location , you can check that in project interpreter , it will show some default location where pycharm is searching to execute exe file , but issue is the exe file is not present at that location , so create the folder which pycharm was expecting to execute exe file and paste the downloaded exe file
Hope it Works for you !!
Happy Coding
Well, i'm pritty new to Python, and I did too had a re-install of my os after a crash
Old setup:
In the old system setup I used python 3.7.4. I made al my (practice)projects with that, and each project had a venv/scripts/python3.7.exe in it.... my undertanding is/was that all the files in these virtual environment where 'stand alone', so sufficient to run a python 3.7.4 for that specific projec files, and not depending on files of the home-python-dir.
The install-directory of python was c:\Program Files (x86)\python 37-32
Each project had a file [project-path]/venv/pyvenv.cfg, and in this file there was the line
home = C:\Program Files (x86)\Python37-32
then - my system crashed - reinstalled windows 10, and downloaded again python, but this time python 3.8, and it installed in C:\Program Files (x86)\Python38-32
New setup:
So, after some hairs lost - I also installed the old python version 3.7.4 in the specific path stated in the pyenv.cfg file (C:\Program Files (x86)\Python37-32). So, i had 2 python versions installed on my new system, one in .../python38-32 and one in .../python37-32
And that worked, so when I selected in 'add interpreter/existing interpreter' and pointed to the [project]/venv/python3.7.exe it worked like a charm.
So, apearantly there are files in each version-specific home-directory that pycharm/python needs - i was under the impression that the files in the .venv directory would be all it needed....
I faced this issue when I switched my system which had different python version installed at different location. The simple short solution is to open 'pyenv' file and point it to the current installation path in your current system and that's it.
I had the same problem and couldn't really figure it out.
As it was a side project the mistake was infuriating and hilarious at the same time.
My folder names had non-english letters. Specifically it had the letter "đ" and the SDK was always invalid because of it.
You might say a stupid mistake, it was, but I wasn't really paying attention.
Hope this helps somebody.
I get the issue in Pycharm 2021.2.3 when I try to make a new environment using an exe that is called anything but python.exe (I was organising my different versions by calling them python39.exe, python38.exe, etc.). I just stopped doing that and renamed all my python exes to python.exe and it started working.
go to the Edit Configuration foe edit interpreter, then remove all interpreter then ok.
now, you should add new interpreter and select the path of python.exe in your installation path(for example c:\ ),then ok.
for me, i solved this error by this solution.
The paths specified in pyvenv.cfg need to be corrected after the venv folder is copied from one computer to another. The main place to look at is the user name. For example:
Old computer:C:\Users\OldComputerUserName\AppData\Local\Programs\Python\Python310
New computer:C:\Users\NewComputerUserName\AppData\Local\Programs\Python\Python310
The path is fixed when you add interpreter to the project the 1st time. I learned it the hard way too.
This problem is because the interpreter path points to the virtual-env, instantiated to the particular project. But we don't have any python installed there.
Therefore we have to set the interpreter path to the "python.exe" file inside the python folder which we have installed on our PC.
This can solve this problem very easily.
If you haven't installed python on your machine please install it and set the path accordingly.
Thank you.
I also had this issue and it's 2023! All I can tell you is what I did to fix it. I tried the other solutions listed in this post (at least the ones I looked at) and they didn't work.
What I did was I copied the venv file in my project (for safekeeping) and then moved it elsewhere.
I deleted the venv file in my project after making my backup and I deleted the interpreter that I had been trying to use.
From there I opened up File -> Settings -> Python Interpreter -> and since there was now no interpreter and no venv folder
I created the interpreter again. Make sure to list the proper path to the version of the python exe you want to use!
From there you pretty much just apply your changes and you will see it pop up with some prompts. It will create a new venv folder for you, just accept the prompts and it worked for me.

PyCharm won't create configuration to run

For the last 2 days PyCharm won't create the configuration setting to run my Python files and I have to create them manually to run my codes.
Before that PyCharm created those configuration setting for me, and all I had to do was just press Shift+F10.
Any ideas?
If you're using Linux or Mac, I've seen a similar (not the same) issue where the app (in this case PyCharm) was installed with root user via sudo and then the executed as normal user, that then won't have permissions to create/change the configuration files, which in PyCharm's case is the .idea folder in your project folder.
If this was previously working, maybe an update to PyCharm while you were running as root may cause the same issue (folder root becomes the owner of the folder and normal user can't change it).

Liclipse/Eclipse: setup debugging environment for a django project alongwith its virtualenv

I am looking for a clearly written set of steps to import an existing django project stored in a GIT repository into Liclipse (Eclipse configured for python) configured using virtualenv and running successfully.
I used File->Import to import an existing project from its top level directory /home/comiventor/ProjectXYZ/ containing .git
Now when I run ProjectXYZ->Django-> Sync DB (manage.py syncdb)
It says "pydev nature is not properly set"
I could not derive much help on this error from any other source. :(
[Update]
I am able to run the django server from eclipse (steps in my answer below) but still not able to make the code stop at breakpoint. :(
[Update]
The error got resolved after setting python environment via
Right Click on Project in Project Explorer -> PyDev -> Source PyDev Project Config
Project Explorer -> Properties -> PyDev Interpreter
Project Explorer -> Properties -> PyDev PYTHONPATH
add exact path within virtualenv where the python site-packages are installed
After this, one also needs to fill two fields in PyDev - Django
Django manage.py = your manage.py file
Django settings module = settings.local or whichever is your settings file
Hope it helps.
I am able to run the django server from eclipse but still not able to make the code stop at breakpoint. :(

PyDev code analysis missing

I have installed Eclipse 3.7.2 from APT in Ubuntu 12.04, and installed PyDev in Eclipse. First, it warns unused import and unused wild import, but it no longer displays them today. However, it can display errors like missing parenthesis.
I created a new user, and installed PyDev using that user, problem still happens. How can I enable them for warnings? I have not change the code analysis settings.
list all operations could solve it here, for others convenience, and make this question closed
remove the project and recreated it, and this time the project dir is the the PYTHONPATH
remove your python interpretor settings, and set it again in eclipse - window preference - pydev -interpreter Python, refresh the pydev index
Project -> Properties -> PyDev -PYTHONPATH, all is empty. I then "add source folder"
I had the same problem. Went to project properties > pydev - PYTHONPATH, then setting the source folder did it for me !

Categories