fixing the path so python can recognize z3 modules - python

I have successfully installed z3 on a remote server where I am not root. when I try to run my python code I get :
ModuleNotFoundError: No module named 'z3'
I understand that I have to add it to PYTHONPATH in order to work and so I went ahead and done that like this:
export PYTHONPATH=$HOME/usr/lib/python-2.7/site-packages:$PYTHONPATH
I still get the same issue though, how can I verify that it was correctly added to the variables environment? what am i doing wrong?

Did you pass the --python flag when you called scripts/mk_make.py?
See the instructions on https://github.com/Z3Prover/z3/blob/master/README.md on how to exactly enable Python (about all the way down in that page). Here's an example invocation:
python scripts/mk_make.py --prefix=/home/leo --python --pypkgdir=/home/leo/lib/python-2.7/site-packages
Change the directories appropriately, of course.

For Windows users that just downloaded and unzipped the compiled Z3 binary into some arbitrary directory, adding the location of the python directory in the directory where Z3 was installed to PYTHONPATH did the trick. ie in Cygwin : $ export PYTHONPATH=<location of z3>/bin/python:$PYTHONPATH (or the equivalent in a Windows command shell)

Related

Invalid python interpreter when using virtualenv --system-site-packages in VSCode

Ideally I would like to use Loading an Lmod module using VSCode with Remote-SSH
however the soultion to use that directly does not seem to work. On the other hand virtualenvs ought to be supported by the Python VSCode extension.
Thus I figured the following steps should work instead.
Set-up the virtualenvironment in the remote environment
$ module load Python
$ virtualenv --system-site-packages my_python
Connect via "Remote - SSH" plugin
In the terminal source your virtual environment from 1 and get the path to the python binary softlink:
$ source my_python/bin/activate
$ which python
/path/to/my_python/bin/python
Copy the path to the python binary and paste it into the path to the Python intepreter that VSCode asks for.
And they do, but not always. The first time I tried this it worked and now everytime I try this for the same host it works directly. However, whenever I change to another host with the same parallel file system and redo step 4 it doesn't and instead says
Invalid python interpreter selected
This is the same error message as when you try to directly point to the python that the is loaded with Lmod (and built with EasyBuild if that makes a difference).
Now I'm stuck because the error message is not very helpful, I haven't found a stacktrace or any log-files that include this error. If I could find that or the code that handles the logic for what is a valid interpreter, that would be really helpful.
In summary:
virtualenv --system-site-packages symlinked Python doesn't work reliably as interpreter when system site Python is not a valid Python interpreter.
How to get this to work reliably?
Alternatively, what is the logic that determines a valid interpreter?

Python conflicts when importing?

I have windows 10 with 2 user accounts, one is an old one that has Python installed. My latest account also has Python installed. I used pip install tweepy, and it now exists in the site packages. If I open my Python shell (v3.6.5), it imports fine. However, I can't get this to work when switching to Python in cmd. In here, after typing python, it says Python 3.6.6. Obviously they are different, yet they seem to be originating from the same directory.
Any ideas?
[edit] I have just realised that I have an external application that runs on Python 3.6.6., so I guess it's defaulting because of that. However, I can't uninstall that since I need it - is there a way to specify which version of Python is launched when I type python into the cmd?
[edit2]: This is the issue, and the solution there works. However, I want to be able to just type python into cmd, rather than the entire path. Since both exist in the path (and I don't want to remove the other 3.6.6.), is there a way to achieve this?
Have you thought about using a virtual environment?
https://virtualenv.pypa.io/en/latest/
When you enter "python" into your cmd it searched python.exe in the directories listed on your PATH variable.
All you need to do is to modify your PATH and add the directory path in which the python with the desired version is located.

Python 2 does not work any more, PYTHONPATH issue?

I use python3 normally but also some python2 with ROS. After a longer time i tried to built my ros workspace and the error I get is
ImportError: "from catkin_pkg.package import parse_package" failed: No module named 'catkin_pkg'
Make sure that you have installed "catkin_pkg", it is up to date and on the PYTHONPATH.
CMake Error at /opt/ros/kinetic/share/catkin/cmake/safe_execute_process.cmake:11 (message):
execute_process(/home/work/py_venv/bin/python
"/opt/ros/kinetic/share/catkin/cmake/parse_package_xml.py"
"/opt/ros/kinetic/share/catkin/cmake/../package.xml"
"/home/work/catkin_ws/build/catkin_tools_prebuild/catkin/catkin_generated/version/package.cmake")
The first directory /home/work/py_venv/bin/python is a virtual environment for python3. I am not sure why it is looking there. I dont have any virtual environment activate (well on purpose at least). What I am totally missing though is the path to the standard python2 installation. Shouldnt it be there?
If I enter echo $PYTHONPATH in the terminal, I just get /opt/ros/kinetic/lib/python2.7/dist-packages
I guess there is something missing? How can I set this variable correctly. Which value does it have at installation?
I recently installed venv in python3 apart from that I am not aware of any changes I did to python since it stoped working.
Now that is a lot of questions.
If you can answer any of them, it would be appreciated.
Edit: I know found the main problem is the prepending of the venv on the path , so that it look for the package in the python3 installation which does not contain the catkin package. How can I remove this from the path?
If you want to remove venv python path, you can do that as follow,
echo $PATH
export PATH=<remove unwanted path>
In this way, you can remove your venv python path.
Also, check this python --version which might be set to python3, if so change that as well.
Finally, check PYTHONPATH if it's not directed proper location change and try.

How do I run my Python script? Why does the command line tell me "no such file or directory"?

I have Python 2.7 installed at C:\Python27 and I have added the path C:\Python27\; to the environment variables and .py: to PATHEXT. I am able to launch Python.
I downloaded a folder google-python-exercises to my desktop, which contains a script hello.py.
Following the advice in the Google Developers course, I try to run the script by using python hello.py at the command prompt.
When I attempt this, I get the message: python: can't open file 'hello.py: [Errno 2] No such file or directory. What is wrong, and how am I supposed to fix it? I found that I can solve the problem by running cmd from the folder, but this seems like a temporary solution.
Python cannot access the files in the subdirectory unless a path to it provided. You can access files in any directory by providing the path. python C:\Python27\Projects\hello.py
I resolved this problem by navigating to C:\Python27\Scripts folder and then run file.py file instead of C:\Python27 folder
Options include:
Run the command from the folder where hello.py is located (this way, hello.py is already a relative path to the file). This is the solution that OP found.
Give a proper path to the hello.py file - either absolute (e.g. C:/Users/me/Desktop/google-python-exercises/hello.py) or relative (for example, google-python-exercises/hello.py, if the current working directory is the desktop).
Add a path to the folder (C:/Users/me/Desktop/google-python-exercises) to the PYTHONPATH environment variable, and run the code as a module (python -m hello).
In all cases, a path is being given directly - Python will not "search" for the file.
From your question, you are running python2.7 and Cygwin.
Python should be installed for windows, which from your question it seems it is. If "which python" prints out /usr/bin/python , then from the bash prompt you are running the cygwin version.
Set the Python Environmental variables appropriately
, for instance in my case:
PY_HOME=C:\opt\Python27
PYTHONPATH=C:\opt\Python27;c:\opt\Python27\Lib
In that case run cygwin setup and uninstall everything python.
After that run "which pydoc", if it shows
/usr/bin/pydoc
Replace /usr/bin/pydoc
with
#! /bin/bash
/cygdrive/c/WINDOWS/system32/cmd /c %PYTHONHOME%\Scripts\\pydoc.bat
Then add this to $PY_HOME/Scripts/pydoc.bat
rem wrapper for pydoc on Win32
#python c:\opt\Python27\Lib\pydoc.py %*
Now when you type in the cygwin bash prompt you should see:
$ pydoc
pydoc - the Python documentation tool
pydoc.py <name> ...
Show text documentation on something. <name>
may be the name of a Python keyword, topic,
function, module, or package, or a dotted
reference to a class or function within a
module or module in a package.
...
Try uninstalling Python and then install it again, but this time make sure that the option Add Python to Path is marked as checked during the installation process.

How to integrate Django and Cygwin?

I have a Windows box with cygwin, python and django installed.
Now I want to run django-admin, but when I do I get the error:
$ django-admin.py
c:\Python26\python.exe: can't open file '/usr/bin/django-admin.py': [Errno 2] No such file or directory
From here
For Windows users, who do not have symlinking functionality available, you can copy django-admin.py to a location on your existing path or edit the PATH settings (under Settings - Control Panel - System - Advanced - Environment...) to point to its installed location.
hope this helps
I just ran into the exact same problem. I've found that if you already have the windows version of python installed, it seems to get priority over the cygwin version. I solved the problem by editing /etc/profile and changed:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:$PATH
...to:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:
...which I think stops cygwin from adding the normal windows path. Once you've got that working, download django into some directory, move into that directory and type:
python setup.py install
I was having problems to begin with because I had omitted the 'python' bit at the start
As for the step on how to start your django in cygwin
first open your windows command prompt
then register the python environment by doing this:
Path %path%;C:\Python27;C:\Python27\Scripts
then now go to the installation folder of your cygwin
cd C:\cygwin
then run the cygwin.bat like this:
C:\cygwin>cygwin.bat <enter>
then cygwin will open, and type python to see if it now working
$ python
Voila we are done!
Sort of sounds like the windows version of Python is trying to run instead of the cygwin one. What happens if you type this:
$ python django-admin.py
Here I'm assuming
$ which python
Finds the cygwin version of python (which will be something like /usr/bin/python).
You may also try (temporarily) uninstalling the windows version of python and use only cygwin.
Help us help you. Is there a reason why you are running the windows python interpreter (c:\Python26\python.exe) as oppose to the cygwin python interpreter (/usr/bin/python.exe)? That could be your problem. So to troubleshoot that, you might consider removing the windows native interpreter or simply making sure the cygwin path is listed before the c:\Python26 path in the windows global PATH variable.
Add the location of your django/bin folder (or wherever else you keep django-admin.py) to your PYTHONPATH environment variable.
Like Brian mentioned you are running the Windows version of Python which won't work with the Cygwin installation.
A word of warning. When I first started using Django, I tried installing it in Cygwin and had a variety of problems and ended up switching to the regular Windows version of Python. Unfortunately, I didn't document all my issues, but I remember some of them had to do with the database libraries. Anyway, that was a few months ago when I knew less about Django than I do now. Maybe the problems I ran into have been solved and perhaps now that I know more I could get it to work, but running Django on Cygwin does seem to be the road less traveled. Good luck. :)
Just copy the django-admin.py to the current location you are working on for e.g
on Cygwin:
<root>/projects/
on your windows directory it will look like this:
C:\cygwin\home\<your computer name>\projects\
once you copy the file, you can create your project by typing this command:
$ python django-admin.py startproject mysite
and that's all - you have completed your first project using the Cygwin linux-like environment.
Add two lines to .bash_profile and .bashrc files (view their difference here). You can find them in C:\cygwin\home\[username]:
export PATH=$PATH:/cygdrive/c/python2.7
export PYTHONPATH=$PYTHONPATH:/cygdrive/c/python2.7/Lib/site-packages
Hope this helps

Categories

Resources