so I have this package. In the cmd I go to hp#HP-PC C:\Users\hp\Documents\scripts:
hp#HP-PC C:\Users\hp\Documents\scripts
> python
Python 3.5.2 |Anaconda 4.1.1 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import toolzz.printer as t
>>> t.printz()
5
Everything is working fine but I want to have a directory in which I could add my scripts and be able to open my cmd->python->import my package and do whatever I am going to do and not get this instead:
hp#HP-PC C:\Users\hp
> python
Python 3.5.2 |Anaconda 4.1.1 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import toolzz
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'toolzz'
>>>
PS: keep in mind I have added the directory scripts to the path and I have global bat files which work
Run
python -m site
It'll list 2 important pieces of information:
The Python module search path, sys.path
The location for the USER_SITE directory, and wether or not this exists.
Python looks for modules along those locations. Put your module in a sys.path location (in one that ends in site-packages preferably), or make sure you created the USER_SITE directory and put your code in there.
And you can always extend the path by setting the PYTHONPATH environment variable.
Related
I am trying to use python and module package on cmd. I could find module directory and start the python program, but the python program opened on cmd did not find the module. I think this problem has occurred because of setting path of module directory is wrong. this is my sys.path on my python program
['', 'C:\Users\skdbs\AppData\Local\Programs\Python\Python37-32\Lib\idlelib', 'C:\Users\skdbs\AppData\Local\Programs\Python\Python37-32\python37.zip', 'C:\Users\skdbs\AppData\Local\Programs\Python\Python37-32\DLLs', 'C:\Users\skdbs\AppData\Local\Programs\Python\Python37-32\lib', 'C:\Users\skdbs\AppData\Local\Programs\Python\Python37-32', 'C:\Users\skdbs\AppData\Local\Programs\Python\Python37-32\lib\site-packages']
and this is what happen in my cmd window
Microsoft Windows [Version 10.0.17134.523]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\skdbs>cd AppData
C:\Users\skdbs\AppData>cd Local
C:\Users\skdbs\AppData\Local>cd Programs
C:\Users\skdbs\AppData\Local\Programs>cd Python
C:\Users\skdbs\AppData\Local\Programs\Python>cd Python37-32
C:\Users\skdbs\AppData\Local\Programs\Python\Python37-32>set PYTHONPATH = C:\Users\skdbs\AppData\Local\Programs\Python\Python37-32\PythonModule
C:\Users\skdbs\AppData\Local\Programs\Python\Python37-32>python
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
'>>> import game
Traceback (most recent call last):
File "<'stdin>", line 1, in <'module>
ModuleNotFoundError: No module named 'game'
'>>>
(P.S. Thank you for reading my poor english)
I downloaded and installed (build + make) a cython package, g2opy successfully. And when I tried checking if everything went well, I get this:
(cv) clmno#machine:~/OpenSource/python/g2opy$ python
Python 3.4.5 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:47:47)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import g2o
>>> import numpy
>>> import cv2
So, I assume everything is fine and opened another terminal window. And tried importing the same module, but failed:
(cv) clmno#machine:~$ python
Python 3.4.5 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:47:47)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import g2o
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'g2o'
Has this to do with the shared library (.so file)? If it was successfully imported, why would it fail the next time?
In the second terminal, you are running Python in a different directory compared to the first terminal. This suggests that the library you built is not in the Python path. It worked in the first terminal because the g2o library is in the directory where you are currently running Python. As Matthieu suggested, add "~/OpenSource/python/g2opy" to your PYTHONPATH environment variable.
In ~/.bashrc, add:
export PYTHONPATH=$PYTHONPATH:path/to/g2opy
then run source ~/.bashrc to update the environment variable in the current path.
If you installed the package locally, you need to set PYTHONPATH. Seems like it's not set properly.
My environment is Windows10, and I installed python3.6, tensorflow, and anaconda.
There is no error in the installation.
If I run the "command prompt" (not use anaconda), I can success to run tensorflow.
However, if I use anaconda, a problem is coming.
1st: If I run anaconda prompt and import tensorflow by python, no problem.
2nd: If I change the folder and import tensorflow, the error message "ModuleNotFouldError" is coming.
Why I change the path, I cannot import a module?
History is below.
(c:\Users\**Username**\Anaconda3) c:\Users\**Username**\>python
Python 3.6.0 |Anaconda 4.3.0 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits", or "license" for more information
>>>import tensorflow
>>>exit()
(c:\Users\**Username**\Anaconda3) c:\Users\**Username**\>cd workspace
(c:\Users\**Username**\Anaconda3) c:\Users\**Username**\workspace>python
Python 3.6.0 |Anaconda 4.3.0 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC 1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits", or "license" for more information
>>>import tensorflow
Trackback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'tensorflow'
My Python 2 environmental path:
C:\Python27
C:\Python27\Scripts
My Python 3 environmental path:
C:\Python35
C:\Python35\Scripts
I set the environmental path for Anaconda2
C:\Users\User\Anaconda2\Scripts
C:\Users\User\Anaconda2
But when i typed python to enter the shell in cmd (C:\Users\user)
Importing the module of Anaconda like numpy or matplotlib
C:\Users\User>python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named numpy
C:\Users\User>cd Anaconda2
C:\Users\User\Anaconda2>python
Python 2.7.12 |Anaconda 4.1.1 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import numpy
>>>
So i don't know
1.Why my module can't import while not in Anaconda2
2.It is said that the path of Python2 will overrdie the Python,so how to enter in the Python35 shell?
thanks everybody
Each Python installation has its own libraries. As you will see, you are not running the same Python 2.7 interpreter when you run with Anaconda active as you are without (I assume that's either the system Python or one you installed yourself).
Libraries installed in one interpreter aren't available to others. You should consider learning about conda environments to allow you to manage multiple projects easily.
The command deactivate should terminate the Anaconda environment, and if the Python 3 interpreter is first on your PATH you should then be able to run it. Another way would be to explicitly use the command
C:\Python35\python
which should work even with Anaconda active.
Caution: it's a long time since I used Windows, and I don't have current information on getting multiple Pythons to live happily together on Windows.
I'm in the early stages of integrating some Python to invoke some computations in Matlab and roll up all the figures into some html generation I'll be doing in ll.xist. I had initially installed Python 2.7.5 32bit, but with a 64bit Matlab R2015a installation I could not install the matlab engine for that version of python. I then downloaded a 64bit version of Python 2.7.9 and tried to do a pip into ll-xist, which was apparently not well maintained and failed. I then downloaded Python 3.4.3 64bit, downloaded the ll.xist installer ll-xist-5.13.win-amd64-py3.4.exe and thought I was good to go. I had to do a pip to pull in cssutils, which succeeded.
Now I come to the point where I invoke my python file from the console. If I invoke it preceded with python everything works fine, if I don't the import isn't recognized. What could account for that discrepancy? Looks like some installation snafu between the various versions I've installed, somehow the python version on the path isn't being called appropriately and I'm guessing the 2.7.9 version of python is being invoked somehow because that install never had ll.xist installed, though my 2.7.5 install did.
C:\Temp>python MyScript.py a.txt b.txt
file1: a.txt
file2: b.txt
C:\Temp>MyScript.py a.txt b.txt
Traceback (most recent call last):
File "C:\Temp\MyScript.py", line 20, in <module>
from ll.xist import xsc
ImportError: No module named ll.xist
Here's a sanity check too...
C:\Temp>python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
C:\Temp>which python
/cygdrive/c/Python34/python
Check the file association for .py. While the proper installation might be in your path, the file association might still be pointing to a different version.
You can check this by importing the sys module in a test script and call print(sys.version). Then run the test script with python test.py and just test.py to see which versions are printed.
Turns out the governing issue here is what is known as the Python Launcher for Windows.
3.4. Python Launcher for Windows New in version 3.3.
The Python launcher for Windows is a utility which aids in the
location and execution of different Python versions. It allows scripts
(or the command-line) to indicate a preference for a specific Python
version, and will locate and execute that version.
From my console, I can see the "default" version via the py command...
C:\Users\me>py
Python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
C:\Users\me>py -3
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Here's the fundamental fix...
The key benefit of this is that a single launcher can support multiple
Python versions at the same time depending on the contents of the
first line.
The first line I had to add in my case to my script was
#! python3
Great commentary linked here for details and motivations behind the Launcher.