Determining the issue regarding python versions for running repo init - python

When I am using repo init to initialize some repo from a source, I keep getting:
Traceback (most recent call last):
File "/home/workspace/.repo/repo/main.py", line 56, in <module>
from subcmds.version import Version
File "/home/workspace/.repo/repo/subcmds/__init__.py", line 38, in <module>
['%s' % name])
File "/home/workspace/.repo/repo/subcmds/upload.py", line 27, in <module>
from hooks import RepoHook
File "/home/workspace/.repo/repo/hooks.py", line 472
file=sys.stderr)
^
SyntaxError: invalid syntax
The following are the python versions I have:
python -V -> 2.7
python3 -V -> 3.6
According to this link, python 3.6 is required starting with repo-1.14 but I'm not certain if that's what my repo version is - didn't have any luck finding a way around determining the version.

Looks like you are running an old repo launcher script version that is incompatible with the latest repo version. To fix this, download the latest repo launcher python script from Google and replace your outdated one.
The launcher script is the executable python script called "repo" and is located in your PATH, usually ~/bin (according to Google's instructions) or ~/.local/bin/. To find out where yours is located, type which repo in the terminal and it will print the script's location.
Let's say your repo script is in ~/bin. To download the script (and make it executable), you can do:
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
Also, you do not need to remove Python 2.7 for repo to work. I use Ubuntu 18.04 and have both Python 2.7 and 3.6 installed as well, and repo runs fine.

Related

Error with TensorFlow MNIST [duplicate]

Since updating from Homebrew Python 2.7.11 (from 2.7.10) I'm suddenly unable to test register my package on PyPi from the PyCharm IDE console.
Running (as an "External Tool")
python -B setup.py register -r pypitest
I now get
Traceback (most recent call last):
File "setup.py", line 22, in <module>
from setuptools import setup
File "/usr/local/lib/python2.7/site-packages/setuptools/__init__.py", line 12, in <module>
from setuptools.extension import Extension
File "/usr/local/lib/python2.7/site-packages/setuptools/extension.py", line 8, in <module>
from .dist import _get_unpatched
File "/usr/local/lib/python2.7/site-packages/setuptools/dist.py", line 16, in <module>
from setuptools.depends import Require
File "/usr/local/lib/python2.7/site-packages/setuptools/depends.py", line 6, in <module>
from setuptools import compat
File "/usr/local/lib/python2.7/site-packages/setuptools/compat.py", line 17, in <module>
import httplib
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 80, in <module>
import mimetools
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
import io as _io
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Process finished with exit code 1
I'm not sure how to proceed. I only get this issue if I execute from within my IDE's console. If I do it directly at the system command line (Terminal on OS X) I have no problems.
OS X 10.11.3; Homebrew Python 2.7.11; PyCharm 5.0.3
tl;dr: Fix this issue by doing one of the following:
type hash -r python, OR
log out and log in.
EDIT: An answer to my related question makes it clear what's happening here. When you install a new version of python, you may need to run hash -r python to tell bash to reset the "cached" location to the python executable.
In my case, I was typing python, which was on my $PATH at /usr/local/bin/python. But bash was still using the old cache location /usr/bin/python. So, the old executable was called, but the new path was provided to python in sys.argv[0]. This means that the old executable was running, but the new sys.executable value caused all the wrong modules to get loaded (including the io module).
I'm having the same problem. I installed python 2.7.11 via an installer from Python.org. Strangely, the issue seems to be related to some subtle difference between how OSX launches python when I invoke it from the shell using the full path vs. using just the word python.
So, for me, this works (invoking python via the full path /usr/local/bin/python):
$ which python
/usr/local/bin/python
$ /usr/local/bin/python -c "import io"
$
... but this doesn't:
$ python -c "import io"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
So, as a workaround, you can try doing the same thing.
Elsewhere, I've posted a separate question about this puzzling behavior. Maybe somehow merely calling python invokes some strange mix of the 2.7.11 executable with the 2.7.10 dylibs??
According to https://github.com/klen/python-mode/issues/634:
I had the same issue, but successfully fixed. In my case I compiled
python and vim with homebrew, when PYTHON_PATH has been specified and
set to one of my dev environments, where I also had some libraries,
including io. Workaround was simple: open new terminal, make sure that
you do not have custom PYTHON_PATH, uninstall python, uninstall vim.
Reinstall both of them.
and
Problem solved.
Culprit is the update from python 2.7.10 to 2.7.11.
If you are using conda package control, simply run "conda install
python=2.7.10" will solve this problem.
This doesn't give the root cause though. Since this happens with _io, this looks like a bug in python 2.7.11 (unlikely, there would be a world-scale outcry and a prompt fix if it was) or some packaging bug or version mismatch specifically with the homebrew version (and maybe some related ones, too).
Try to import _io in the console and if it succeeds, check if it was loaded from the same path.
Reinstall python.
brew unlink python && brew reinstall python
Secure the path
export PYTHONPATH=$PYTHONPATH:/usr/local/bin/
BACKUP and Change the order of "paths" file.
sudo nano /etc/paths
it seems, the order of paths, it is decisive to run python properly. In my case, the result was:
#sudo nano /etc/paths
/usr/bin
/usr/local/bin
/bin
/usr/sbin
/sbin
On my mac, path is like this.
$ which python
/usr/local/bin/python
Now I can run both:
$ /usr/local/bin/python -c "import io"
$ python -c "import io"
I had the same issue, it is successfully fixed by just replacing the _io.so file.
sudo find / -name _io.so
copy the path of the _io.so file which DOES NOT belong to python-2.7.11. For example, copy the path of _io.so which is under python-2.7.5:
/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Replace the /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so file with the _io.so that you just found.
This happened to me as well in MacVim. I solved it by making sure :python print(sys.path) is using system Python (e.g. /Library/Python/2.7/...)
Since I installed MacVim via Homebrew, I just did that by:
Spawn a new shell that had which python -> /usr/bin/python. For my case I needed to remove the pyenv line from my .bash_profile. If you installed Python via Homebrew you may want to brew unlink python first
brew reinstall macvim
If your problem is caused by anaconda, it is unnecessary to remove //anaconda directory.
Just open your ~/.bash_profile, find the line
export PATH="//anaconda/bin:$PATH
and comment it out, then restart your terminal session.
Another quick workaround if you don't mind sticking with Python 2.7.10 is to specify the path of the Python interpreter executable that will be used for the virtualenv. On OSX that path is usually /usr/bin/python:
virtualenv venv --python=/usr/bin/python
Can't add comment (?) so this just to share my exp., downgrade to 2.7.10 works fr me.
I got this error after a failed NLTK download, I needed to uninstall anaconda:
sudo rm -rf ~/anaconda
update PATH variable
This happened when I already had tried to create a venv in a folder, and mistakenly was trying to initialize a second one! So I just removed venv directory and re-ran the command. Very likely this is not the answer to this solution, but searching my error brought me here, so it may help some others who are stuck.
I solved this issue by removing the symbolic link that was in /usr/local/bin and copying the actual python binary, that was pointed to by said link, there.
I had the same issue when I tried to use PyCharm. Solved by setting "python interpreter" in project configuration to point to the python virtual env I wanted to use, which was an Anaconda env. Somehow the interpreter path was missing the "anaconda" portion of ~/.../anaconda/.../_io.so. No need to uninstall anaconda.

Python GUI2Exe Application Standalone Build (Using Py2Exe)

I am trying to build a Python Script into a stand alone application. I am using GUI2Exe. My script uses selenium package. I have it installed.
Project compiles fine and runs on python command line directly but fails to build a stand alone because it is referring to folder:
ERROR: test_file_data_extract (__main__.FileDataExtract)
----------------------------------------------------------------------
Traceback (most recent call last):
File "File_data_extract.py", line 18, in setUp
File "selenium\webdriver\firefox\firefox_profile.pyc", line 63, in __init__
IOError: [Errno 2] No such file or directory: 'C:\\users\\username\\PycharmProjects\\Python_27_32bit\\file_data_extract\\dist\\File_data_extract.exe\\selenium\\webdriver\\firefox\\webdriver_prefs.json'
It is looking for selenium package is located at :
C:\Users\username\Anaconda2_Py27_32bit\Lib\site-packages\selenium-2.48.0-py2.7.egg\selenium\webdriver\firefox
where C:\Users\username\Anaconda2_Py27_32bit is where I installed Anaconda Python 2.7, 32 bit version. By default it is looking for in \dist\filename.exe folder.
I was able to build it using bbfreeze. It works great.
First I had to install bbfreezee via pip (one time only):
pip install bbfreeze
Create a build_package.py file as:
from bbfreeze import Freezer
f = Freezer("project_name", includes=("selenium","SendKeys",)) #list problem packages here to manually include
f.addScript("project_name_script.py")
f() # starts the freezing process
Build project:
python build_package.py bdist_bbfreezee
in folder project_name where project_name_script.py sits you find project_name_script.exe with all the include packages including selenium and sendkeys. When you distribute the package you need to distribute entire project_name because it contains all dependent library dlls (python .pyd).
More details refer official bbfreezee here:
https://pypi.python.org/pypi/bbfreeze/#downloads

pycallgraph with pycharm does not work

I'm using mac os x and trying to setup pycallgraph.
Ive installed pycallgraph with pip and graphviz with homebrew.
Everything works from shell.
But not from pycharm.
from pycallgraph import PyCallGraph
from pycallgraph import Config
from pycallgraph import GlobbingFilter
from pycallgraph.output import GraphvizOutput
config = Config()
config.trace_filter = GlobbingFilter(exclude=[
'pycallgraph.*',
])
graphviz = GraphvizOutput(output_file='filter_exclude.png')
with PyCallGraph(output=graphviz, config=config):
def my_fun():
print "HELLO"
my_fun()
/Users/user/Projects/py27/bin/python /Users/user/Projects/py27_django/test2.py
Traceback (most recent call last):
File "/Users/user/Projects/py27_django/test2.py", line 15, in <module>
with PyCallGraph(output=graphviz, config=config):
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 32, in __init__
self.reset()
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 53, in reset
self.prepare_output(output)
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 97, in prepare_output
output.sanity_check()
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/output/graphviz.py", line 63, in sanity_check
self.ensure_binary(self.tool)
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/output/output.py", line 96, in ensure_binary
'The command "{}" is required to be in your path.'.format(cmd))
pycallgraph.exceptions.PyCallGraphException: The command "dot" is required to be in your path.
Process finished with exit code 1
Here:
/Users/user/Projects/py27/ -> virtualenv dir
/Users/user/Projects/py27_django/ -> project dir
What does it want from me?
Install graphviz in MacOS by using:
brew install graphviz
or in Ubuntu by using:
sudo apt-get install graphviz
Then you can test dot by using:
dot -v
You can also download pkg from here
The answer is:
In menubar:
Pycharm -> Run -> Edit Configurations...
In dialog:
for selected .py file or for Defaults/Python:
Environment field group:
Environment variables > ... -> + ->
Add entry:
Name: PATH
Value: /usr/local/bin
Include print environment variables should be selected
FWIW, this is a behaviour which two other users have filed as an Issue in PyCharm's bugtracker: https://youtrack.jetbrains.com/issue/PY-17816
I'll update this post if the developers comment there.
[Update] On September 22nd 2016, Pycharm developers offered a fix in the Early Access version. https://blog.jetbrains.com/pycharm/2016/09/pycharm-2016-3-eap-is-available-with-initial-support-for-python-3-6/, but this does not seem to have fixed the problem yet.
This process worked for my environment; I got the same "dot" error after I compiled. Unfortunately, I was looking for a visual representation of the code which shows inheritance, function calls, more like a flow chart. On the UP-and-UP, I Understand what a profiler does this one worked great!
Pycharm: 2020.3.3
Python 3.8
PyCallGraph3
Venv Environment in Pycharm
For it to work in PyCharm on Windows 10:
Install the package under your interpreter: pycallgraph3
File > Settings > Project > Python Interpreter
Install the program called GraphViz (https://graphviz.org/)
Under your Run/Debug Configurations go to Environment Variables:
Paste the following line at the end of the massive list
;C:\Program Files\Graphviz\bin;
After here, I didn't test its validity but did it anyway if it didn't work try adding it to your windows path.
In Windows under:
System Properties > Environment Variables
FOR USER WINDOW (TOP)
Edit > PATH > NEW> add Entry: C:\Program Files\Graphviz\bin\
FOR SYSTEM VARIABLES WINDOW (BOTTOM):
Edit > PATH > NEW > add a New Entry: C:\Program Files\Graphviz\bin\

Python bindings for libtorrent-rasterbar are not working

I'm running Debian 6.0.6
I've downloaded latest version of libtorrent-rasterbar from here: http://code.google.com/p/libtorrent/downloads/detail?name=libtorrent-rasterbar-0.16.6.tar.gz&can=2 and installed it:
./configure --enable-python-binding
make
make install
cd bindings/python
python setup.py build
python setup.py install
now I want to test whether the library works:
>>> import libtorrent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libtorrent-rasterbar.so.7: cannot open shared object file: No such file or directory
The packaged version of libtorrent from the distributive's repository had some funny behaviour (complaining on boost dependences), so I've decided to upgrade. The same situation is on both of my debian boxes, yet ubuntu box is fine.
old error message from my debian box:
File "ar.py", line 15, in create
s.start_dht()
Boost.Python.ArgumentError: Python argument types in
session.start_dht(session)
did not match C++ signature:
start_dht(libtorrent::session {lvalue}, libtorrent::entry)
Search for the shared object file and add it to your path.
sudo updatedb
locate libtorrent-rasterbar.so.7
This should output /<path_to_directory>/libtorrent-rasterbar.so.7
Add this to your ~/.profile or temporarily tell Python where to look:
export LD_LIBRARY_PATH=/<path_to_directory>/
See more detailed installation instructions here.

error in running Google apps in python in windows OS

in google app engine
get error in runing the appicaition
in logs of googleappengine
2012-04-21 13:24:04 Running command: "['C:\Python32\pythonw.exe', 'C:\Program Files\Google\google_appengine\dev_appserver.py', '--admin_console_server=', '--port=8080', 'C:\udacity\googleapps\hello-udacity']"
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\dev_appserver.py", line 125, in
run_file(file, globals())
File "C:\Program Files\Google\google_appengine\dev_appserver.py", line 121, in run_file
execfile(script_path, globals_)
NameError: global name 'execfile' is not defined
2012-04-21 13:24:07 (Process exited with code 1)
You appear to be running Python 3.2 (your Python executable is on this path 'C:\Python32\pythonw.exe').
Google AppEngine requires Python 2.5 or 2.7 at this stage, see this article. You need to download Python 2.7, install it in a parallel directory, and make it the default executable.
You may find it helpful to read this answer on running more than one version of Python
Also, I had the same problem. This is because I have installed both Python 2.7 and Python 3.x (the latest version of the framework Django uses the latter). I installed Python 3.x later so this is the version that is used by default in my system. To use Python 2.7 you could do the following:
C:\Python27\python.exe dev_appserver.py path-to-your-app
Notice that here
C:\Python27\python.exe
is the path to the python 2.7 executable (in my case, but this could vary).
I did that and it worked.
More info and reading here.

Categories

Resources