naoqi 2.5.5.5 and PyCharm CE 2017.1 - python

I have an annoying problem with PyCharm CE and naoqi. Following the installation instructions in Aldebaran Guide, I have configured my environment to work with this one.
I have installed the version of python (python 2.7.13) suggested by Aldebaran, I have written the .bash_profile using:
# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
#NaoQI 2.5.5
export PYTHONPATH=${PYTHONPATH}:/Users/francesco/Documents/PyLibs/pynaoqi-python2.7-2.5.5.5-mac64/lib/python2.7/site-packages
export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:/Users/francesco/Documents/PyLibs/pynaoqi-python2.7-2.5.5.5-mac64/lib
after that, I launch my code in python from Terminal (making sure that the right version of python is called when I type
$ python my_code.py
and all is working (I tried also with virtualenv and all works fine if I launch all from terminal).
So far so good but then comes the poison arrow. I use PyCharm CE like IDE, I have created a new project that use the same environment that works fine in terminal and the magic happens..
The first issue is:
/Users/francesco/Documents/PyEnv/pynaoqi255_python2713/bin/python /Users/francesco/PycharmProjects/PepperRobot/PepperRobot.py
Traceback (most recent call last):
File "/Users/francesco/PycharmProjects/PepperRobot/PepperRobot.py", line 5, in
import qi
ImportError: No module named qi
(Ok seriuosly this is the same environment that in terminal works)
I try to bypass the problem, adding the content of naoqi sdk in the virtualenv's site-package. Ok, the problem is bypassed.. But there is another problem:
/Users/francesco/Documents/PyEnv/pynaoqi255_python2713/bin/python /Users/francesco/PycharmProjects/PepperRobot/PepperRobot.py
Traceback (most recent call last):
File "/Users/francesco/PycharmProjects/PepperRobot/PepperRobot.py", line 5, in
import qi
File "/Users/francesco/Documents/PyEnv/pynaoqi255_python2713/lib/python2.7/site-packages/qi/init.py", line 88, in
from _qi import Application as _Application
ImportError: dlopen(/Users/francesco/Documents/PyEnv/pynaoqi255_python2713/lib/python2.7/site-packages/_qi.so, 2): Library not loaded: #loader_path/libqipython.dylib
Referenced from: /Users/francesco/Documents/PyEnv/pynaoqi255_python2713/lib/python2.7/site-packages/_qi.so
Reason: image not found
Process finished with exit code 1
I did not understand why...
I have also include in
Preferences -> console -> Python Console -> Environment Variables
the same variables included in .bash_profile but to no avail.
How can I solve this tedious problem ?

I have solved my problem editing run/debug configuration and putting here the environment variable DYLD_LIBRARY_PATH. All works fine.

Related

ImportError: No module named pygments.styles when attempting to run Pythontex

When I try to run pythontex via my command line((base) Zachs-MacBook-Pro:mat_300 zachmaurus$ pythontex pythontex.tex) the following occurs:
Traceback (most recent call last):
File "/Library/TeX/texbin/pythontex", line 50, in <module>
import pythontex2 as pythontex
File "/usr/local/texlive/2019/texmf-dist/scripts/pythontex/pythontex2.py", line 61, in <module>
from pygments.styles import get_all_styles
ImportError: No module named pygments.styles
How do I go about solving this issue? I have downloaded pygments with pip install, but for whatever reason when I attempt to run the script the module pygments.style cannot be found.
Solved this issue by adding pythontex_install.py to my PATH using export PATH=$PATH:/usr/zachmaurus/Downloads/pythontex/pythontex_install.py in MacOS Terminal. To ensure that pythontex_install.py has been added to PATH environment run echo $PATH and it should appear as one of the variables. After having added pythontex_install.py to PATH, I now get the following result when I run pythontex pythontex.tex to compile my document:
This is PythonTeX 0.16
--------------------------------------------------
PythonTeX: pythontex - 0 error(s), 0 warning(s)
I solved this problem by explicitly call the interpreter I want, wenn I compile the document.
pdflatex -interaction=nonstopmode document.tex
python3 <path_to_pythontex.py>/pythontex.py document.tex
pdflatex -interaction=nonstopmode document.tex
or for any python interpreter you want:
pdflatex -interaction=nonstopmode document.tex
<path_to_python>/python3 <path_to_pythontex.py>/pythontex.py document.tex
pdflatex -interaction=nonstopmode document.tex
Of course Pygments module schuld be installed by this interpreter. This worked very good for me on macOS.
I got the same problem when I tried to use pythontex on my macbook (on macOS Catalina 10.15).
What I suggest below must be (if used) used with precaution :
I tried so many solutions and what actually worked for me was this :
I made sure that pygments was installed on my machine (I ran 'pip install pygments' on the terminal)
Then I changed the first line of the files pythontex, pythontex2 (because the problem seemed to come from there) and pythontex3
Theses files (if you are using macOS Catalina 10.15 like me) should be in
/usr/local/texlive/2021/texmf-dist/scripts/pythontex
(if you installed TexLive2021) -> you should be able to retrieve this path when you try to compile your tex file anyway...
The first line was replaced by #!/usr/bin/python3 (to ensure that python3 was used instead of python 2.7 which is used by default by macOS) inside the 3 files pythontex, pythontex2 and pythontex3 then :
I ALSO added this line (see the screenshot below) in pythontex3 :
sys.path.append('/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/')
to ensure that python found the module pygments
(because I installed python3.9 on my machine and the folder "pygments" and its subfolder "styles" was present in the folder "site-packages")
pythontex3 file
So now everything is working fine again and I can use pythontex =)

VS Code - Configure Run Python File In Terminal

I have a python environment called nem that I created using Conda, however in VS Code when I right click and select 'Run Python File in Terminal' I get the below error. BUT I know this package is not an issue as I can open up a new windows terminal outside of VS Code and run the commands below and everything works great.
activate nem
python index.py
I have also had issues where the output in the terminal is being suppressed even though the application is running. I'm not sure what the root cause of this is, and whether its directly related to Conda. However does anyone know of a solution to this? Or how to configure VS Code's 'Run Python File in Terminal' to just use the commands above.
Windows PowerShell Copyright (C) Microsoft Corporation. All rights
reserved.
PS C:\Users\nikhil\Git Repos\natatorium-energy-model> conda
activate nem PS C:\Users\nikhil\Git
Repos\natatorium-energy-model> &
C:/Users/nikhil/AppData/Local/Continuum/anaconda3/envs/nem/python.exe
"c:/Users/nikhil/Git Repos/natatorium-energy-model/index.py"
Traceback (most recent call last): File "c:/Users/nikhil/Git
Repos/natatorium-energy-model/index.py", line 8, in
from apps import analyse File "c:\Users\nikhil\Git Repos\natatorium-energy-model\apps\analyse.py", line 17, in
import pyarrow.parquet as pq File "C:\Users\nikhil\AppData\Local\Continuum\anaconda3\envs\nem\lib\site-packages\pyarrow__init__.py",
line 49, in
from pyarrow.lib import cpu_count, set_cpu_count ImportError: DLL load failed: The specified module could not be found. PS
C:\Users\nikhil\Git Repos\natatorium-energy-model>
In the bottom left corner, change the python interpreter to the one in your environment.

Pycharm doesn't copy root folder to PYTHONPATH

I'm using Pycharm community edition 2017.3 in Windows 10.
I'm running Python 2.7 with venv.
Till today all was good, but all of a sudden, PyCharm stopped adding the root folder to PYTHON path, and things stopped working (unless I add it manually to sys.path). I haven't change anything in the PyCharm configuration (at least not explicitly...). I tried closing and reopening PyCharm, reboot, clear the cache, cleaning Python compiled files, setting the root folder as 'sources root', but none seems to work.
The same code exactly is deployed on another computer and it's working.
This is the bad line:
from TM2_VAL_LAB import test_base, robot_handler
And this is the error:
Traceback (most recent call last):
File "C:/Users/baruchl/Documents/_GIT/TM2_VAL_LAB/TM2_VAL_LAB/test_vr_translation_ff.py", line 17, in <module>
from TM2_VAL_LAB import test_base, robot_handler
ImportError: No module named TM2_VAL_LAB
When I run the following during the python execution:
print os.getenv('PYTHONPATH')
I get:
None
When I run the same code in the remote computer (where everything running smoothly), I get:
C:\GIT\TM2_VAL_LAB
which is the root folder of the python script I'm running.
This is the run configuration I'm using:
This is how my project looks like:
Any ideas?
After few back and forth with PyCharm rep, the solution is to close PyCharm, rename/delete the .idea folder and re-open PyCharm.
That's it.
After this, when when running the same file as before,
print os.getenv('PYTHONPATH')
results in:
C:\Users\baruchl\Documents\_GIT\TM2_VAL_LAB
and
print sys.path
results in:
['C:\\Users\\baruchl\\Documents\\_GIT\\TM2_VAL_LAB\\TM2_VAL_LAB', 'C:\\Users\\baruchl\\Documents\\_GIT\\TM2_VAL_LAB', ...]

$PYTHONPATH not working on OSX

I have been at this for a day and have found no solution. My python project is very levels deep and some of the modules have to be run independently (no -m flag, no relative imports). For this reason we decided to add the root folder to the PYTHONPATH. I am running OSX 10.11.3. Everything had been running smoothly until yesterday. I could run independent modules from the terminal with no issues in both Python 2.7 and 3.5. Yesterday, without modifying my PYTHONPATH or any other environment setting, running any of these independent modules from the terminal now gives me import errors in both Python 2 and 3.
Here is my working tree:
/Users/sintrafico/Documents/code/central_maestra
- reports_server.py
- api_server.py
- sintrafico
- sql
- SQLConnection
- api
- incident
- csv (not package)
- independent_module
- tests
I was running my tests yesterday with coverage with no problem, but now I can't.
Python 2 python csv/independent_module.py gives error:
Traceback (most recent call last):
File "csv/independent_module.py", line 13, in <module>
from sintrafico.sql import SQLConnection
ImportError: No module named sintrafico.sql
Python 3 python3 csv/independent_module.py gives error:
Traceback (most recent call last):
File "csv/create_bemobile_csv.py", line 13, in <module>
from sintrafico.sql import SQLConnection
ImportError: No module named 'sintrafico'
From within the incident folder, yesterday this command was working fine: coverage run -m unittest discover. Now all the tests fail because ImportError: No module named 'reports_server'.
Since that started happening yesterday, I have been messing with my PYTHONPATH. I left it blank and it didn't work (as expected), I have added the path now several ways:
export PYTHONPATH=“${PYTHONPATH}:/Users/sintrafico/Documents/code/central_maestra"
export PYTHONPATH=“/Users/sintrafico/Documents/code/central_maestra:${PYTHONPATH}"
export PYTHONPATH=“${PYTHONPATH}:/Users/sintrafico/Documents/code/central_maestra/"
export PYTHONPATH=“/Users/sintrafico/Documents/code/central_maestra:${PYTHONPATH}"
And also setting it without appending the PYTHONPATH since it was empty to begin with. I restarted my computer several times with no success. Also note, I have a .bash_profile and .bashrc with the following contents:
# Setting PATH for Python 3.5
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
PYTHONPATH=“/Users/sintrafico/Documents/code/central_maestra:${PYTHONPATH}“
export PYTHONPATH
And lastly, what bugs me the most is that if I run the tests inside PyCharm they all run and pass, I get no import errors at all.
Have you tried setting the path without the quotes and braces? You are setting the python path as a string representation of the path instead of a list of paths

importError using a virtualenv from cmd on Windows

trying to run a flask dev server on localhost:5000 using a virtualenv on Windows 7
In my command line in the project directory, i activated the virtualenv with the command "env\scripts\activate". It seemed to work, as my next line was preceded with an (env) tag. When I attempted to run the app file (bank_app), however, I got an import error.
Here's the console log
C:\Users\TJ\Documents\Python Projects\TestingPython> env\scripts\activate
(env) C:\Users\TJ\Documents\Python Projects\TestingPython> bank_app
Traceback (most recent call last):
File "C:\Users\TJ\Documents\Python Projects\TestingPython\bank_app.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask
and here's a gist of the bank_app file (just in case it's relevant)
I'm used to running the code directly from PyCharm, which handles the virtualenv for me. it works fine running directly from PyCharm
This is probably related to how Windows maps extensions to executables.
You started the script with bank_app, which is really not the name of your script (your script has a .py extension I assume?). Windows must be doing a search in your directory, and then starting the script with the interpreter that is registered for the .py extension of the script, which is the globally installed interpreter, not the interpreter that is currently in the PATH.
I'm pretty sure if you run the command as python bank_app.py everything will work just fine.

Categories

Resources