I'd like to install tensorflow using pip in python 3.7 on windows 10 using the command-line as administrator.
First time installing tensorflow and I get error messages:
(SyntaxError: unexpected character after line continuation character) or (SyntaxError: invalid syntax).
I have tried the various ways shown below:
# OPENING PYTHON AS ADMINISTRATOR
C:\WINDOWS\system32>C:\Users\plain\AppData\Local\Programs\Python\Python37-32\python.exe
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
# ATTEMPT 1
C:\> pip3 install --upgrade tensorflow
File "<stdin>", line 1
C:\> pip3 install --upgrade tensorflow
^
SyntaxError: unexpected character after line continuation character
# ATTEMPT 2
C:\> pip install --upgrade tensorflow
File "<stdin>", line 1
C:\> pip install --upgrade tensorflow
^
SyntaxError: unexpected character after line continuation character
# ATTEMPT 3
python -m pip install [tensorflow]
SyntaxError: invalid syntax
# ATTEMPT 4
C:\WINDOWS\system32>C:\Users\plain\AppData\Local\Programs\Python\Python37-32\> pip3 install --upgrade tensorflow
SyntaxError: unexpected character after line continuation character
# ATTEMPT 5
C:\WINDOWS\system32>C:\Users\plain\AppData\Local\Programs\Python\Python37-32> pip install --upgrade tensorflow
SyntaxError: unexpected character after line continuation character
Thanks!
python -m pip install tensorflow
works well on my windows7 system. I am currently using python3.6 64 bit version.
Before you execute "python -m pip install tensorflow" from commandline, set the "PATH" in environment variable to 'python.exe'
Related
I am trying to access a python file created on PyCharm with my terminal. When I import modules on PyCharm they are found and successfully imported (e.g tkinter, PIL etc.). When I try to run the file on my terminal I get the following message :
Traceback (most recent call last):
File "THE_project_GUI.py", line 3, in <module>
from PIL import Image
ImportError: No module named PIL
The which python command returns : /usr/bin/python
The which -a pip command returns : /usr/local/bin/pip
How do make sure I use the interpreter that pip is installing for?
Trial:
tromgy's solution:
me#mahmouds-mbp-2 ~ % ln -s -f /usr/local/bin/python3.8 /usr/local/bin/python
me#mahmouds-mbp-2 ~ % cd /Users/me/Documents/Programming/THE_project
me#mahmouds-mbp-2 THE_project % /usr/local/bin/python3.8 /usr/local/bin/python THE_project_GUI.py
returns:
File "/usr/local/bin/python", line 1
SyntaxError: Non-UTF-8 code starting with '\xcf' in file /usr/local/bin/python on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
v0idbar's solution:
I have installed python 3.7 using :
brew install python#3.7
returns :
Python has been installed as
/usr/local/opt/python#3.7/bin/python3
Unversioned symlinks python, python-config, pip etc. pointing to
python3, python3-config, pip3 etc., respectively, have been installed into
/usr/local/opt/python#3.7/libexec/bin
You can install Python packages with
/usr/local/opt/python#3.7/bin/pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages
I have changed the Pycharm interpreter by going to File> New project settings> Preferences for new projects. And then added 3.7 after finding it using /usr/local/opt/python#3.7/bin/python3.
Then I ran the following :
me#mahmouds-mbp-2 THE_project % /usr/local/opt/python#3.7/bin/python3
/usr/local/opt/python#3.7/bin/python3
Python 3.7.11 (default, Jul 6 2021, 12:43:19)
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> /usr/local/opt/python#3.7/bin/python3 THE_project_GUI.py
File "<stdin>", line 1
/usr/local/opt/python#3.7/bin/python3 THE_project_GUI.py
^
SyntaxError: invalid syntax
Try run pip -V to figure out what python version it is using:
$ pip -V
pip 19.0.1 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
You can check if it the same version as the python executable you are using: python -m pip -V
$ python -m pip -V
pip 9.0.1 from /Users/lev/anaconda2/lib/python2.7/site-packages (python 2.7)
You probably have a mismatch between those versions.
This question already has answers here:
ImportError: cannot import name main when running pip --version command in windows7 32 bit
(16 answers)
Closed 2 years ago.
I'm using python 3.6. Pip is installed along with python. Seems like pip isn't showing up. Tried various solutions available here nothing worked. Please help me solve this.
Verifications done:
Path is set as C:\Program Files\Python36\Scripts
Added host entries for all 3
PIP error:
C:\Users\>pip
Traceback (most recent call last):
File "c:\program files\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\program files\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Program Files\Python36\Scripts\pip.exe\__main__.py", line 5, in <module>
ImportError: cannot import name 'main'
Tried solutions:
pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org {package name}
C:\Users\>pip
Traceback (most recent call last):
File "c:\program files\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\program files\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Program Files\Python36\Scripts\pip.exe\__main__.py", line 5, in <module>
ImportError: cannot import name 'main'
C:\Users>python3 -m pip uninstall pip setuptools
'python3' is not recognized as an internal or external command,
operable program or batch file.
C:\Users>python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> python3 -m pip uninstall pip setuptools
File "<stdin>", line 1
python3 -m pip uninstall pip setuptools
^
SyntaxError: invalid syntax
>>> python3 -m pip uninstall pip setuptools
File "<stdin>", line 1
python3 -m pip uninstall pip setuptools
^
SyntaxError: invalid syntax
>>> pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org {package name}
File "<stdin>", line 1
pip install --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org {package name}
^
SyntaxError: invalid syntax
>>>
Using below version
C:\Users\>python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Try using
pip2
For python 2. And
pip3
For python 3
And do it from an admin cmd line.
Check you have added paths to the these directories (if you are using python3.x versions) -
C:\Users\tojose\AppData\Local\Programs\Python\Python3.x and for pip
C:\Users\tojose\AppData\Local\Programs\Python\Python3.x\Scripts as pip*.exe's are
stored here.
Try to use the full path for both pip and the package you want to install.
Example (for Python 3.6):
C:\Python36\Scripts\pip install C:\Python36\requests-2.18.4-py2.py3-none-any.whl
On Windows 10, I had the same problem. PIP 19 was already installed in my system but wasn't showing up. The error was No Module Found.
python -m pip uninstall pip
python -m pip install pip==9.0.3
Downgrading pip to 9.0.3 worked fine for me.
I already answered it HERE
I had the same issue and have tried several commands without a result. I just simply upgraded my pip version from 19.10 to version 20.3.3 and now it's working fine.
python -m pip install --upgrade pip
(for windows)
Note: you are applying the pip command inside the Python REPL, which is wrong.
By using exit() function come out from Python and write like this.
In my case I have already installed a new version.
Hello thanks for looking.
i am trying to import third party modules but having a hard time.
I have already done the edit to the environment variable and i get python to show up in cmd but I can not find the correct syntax to do the install.
based on the python org site i should use python -m pip install SomePackage
i have also read that i should use pip install SomePackage
I have tried both and have not had success. I am in windows 10 below is the command prompt of my attempts.
C:\Users\T****J>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> -m pip install send2trash
File "<stdin>", line 1
-m pip install send2trash
^
SyntaxError: invalid syntax
>>> pip install send2trash
File "<stdin>", line 1
pip install send2trash
^
SyntaxError: invalid syntax
>>> python pip install send2trash
File "<stdin>", line 1
python pip install send2trash
^
SyntaxError: invalid syntax
>>> python -m pip install requests
File "<stdin>", line 1
python -m pip install requests
^
SyntaxError: invalid syntax
>>>
thanks again. searched the best i could and maybe i am missing something easy. I am new at this .
you are trying to give command line arguments within the interpreter...
If PIP is installed, you don't need to invoke the interpreter at all. Simply call:
C:\Users\T****J>pip install send2trash
from the command prompt.
otherwise, if you are using the pip module, you need to pass the command line arguments to the command line not to the interpreter...
C:\Users\T****J>python -m pip install send2trash
pip is a program itself, similar to how npm, bundler or nuget works.
What you are currently doing is firing up the Python interpreter, and writing the call to pip from there, it doesn't work like that.
What you're looking to do is to install a package with pip, like this:
C:\Users\T****J>pip install send2trash
and after that's done you can open the interpreter again and import the module like this:
C:\Users\T****J>python
>>> import send2trash
I strongly suggest, however, that you do a bit of research into virtualenv and how to use it, it will make your life easier on the long run
I'm testing newly installed 'xlrd' package :
#!/usr/bin/env/python
import xlrd
wb = xlrd.open_workbook('D:\excel\test.xls')
print (wb.sheets())
I run it through IDLE (Windows 7) and I get the following error message:
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Traceback (most recent call last):
File "D:\excel\testxls.py", line 3, in <module>
import xlrd
File "C:\Program Files (x86)\Python33\lib\site-packages\xlrd\__init__.py", line 1187
print "EXTERNSHEET(b7-):"
^
SyntaxError: invalid syntax
>>>
Any idea on this issue?
Thanks!
It seems like your xlrd file is corrupted. So update it by using the following command :
$ python3 -m pip install --upgrade xlrd
XLRD is available for Python3.
You can get it with sudo apt-get install python3-xlrd or with sudo pip3 install xlrd
As you can see it's available here on pypi : https://pypi.python.org/pypi/xlrd
Here's a dump of my console output :
sudo apt-get install python3-xlrd
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-xlrd is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 574 not upgraded.
It seems that there is an error with your installation or usage.
The first thing I have seen is that print 'something' is not used in python3 but print('something'). And the error shown in the code is because of using python2 with python3.
At the time of writing this answer the version of xlrd is 0.9.4. This version is compatible with both python2 and python3.
So I suggest you to update the xlrd module so that you will not face any further errors. You can do that by following any of the following steps:
$ pip install xlrd
or
$ easy_install xlrd
I'm trying to install ntlk for a Django project. I followed the intstructions on NTLK's website, and I they worked because when I try to install again with pip, I get:
➜ Word_Maker git:(master) sudo pip install -U numpy
Requirement already up-to-date: numpy in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages
Cleaning up...
➜ Word_Maker git:(master) sudo pip install -U pyyaml nltk
Requirement already up-to-date: pyyaml in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages
Requirement already up-to-date: nltk in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages
Cleaning up...
However, when I do import ntlk from python3, I get:
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 16 2013, 23:39:35)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/nltk/__init__.py", line 37
except IOError, ex:
^
SyntaxError: invalid syntax
^
SyntaxError: invalid syntax
import numpy works, however. Any help would be appreciated!
It seems you made a spelling mistake:
Requirement already up-to-date: nltk in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages
And you're trying to import ntlk. Try using import nltk.
As for the import error, the following from their website:
NLTK requires Python versions 2.6-2.7. (A version supporting Python 3 is available at http://nltk.org/nltk3-alpha/).
So NLTK does not (yet) support python 3.3 fully.
First remove NLTK using pip: sudo pip uninstall nltk
Then download the source. And install using sudo python setup.py install
And try again. Be aware this is an alpha, so expect some methods to randomly throw errors or generate unexpected output.
If you still have this error after fixing the spelling, the issue is that PyPI is installing an older NLTK package (2.x). Check this by looking at the first message in the terminal immediately after your run sudo pip install nltk.
To install the latest version of NLTK (3.x) that is compatible with Python 3, first sudo pip uninstall nltk.
Then use:
sudo pip install nltk==3.0.0b2
The latest version number is found here: https://pypi.python.org/pypi/nltk
Sometimes the versions of dependent packages may cause issues. The main issue is old, but I found a slightly different problem when using the parser - which internally was going into scipy. Solved using:
pip3 uninstall nltk scipy matplotlib
pip3 install -U nltk scipy matplotlib